comp.lang.ada
 help / color / mirror / Atom feed
From: Dirk Herrmann <fight_spam@invalid.invalid>
Subject: Re: conversions between fixed-point types
Date: Sat, 19 Sep 2009 14:41:49 +0200
Date: 2009-09-19T14:41:49+02:00	[thread overview]
Message-ID: <h92jie$q4g$1@news.albasani.net> (raw)
In-Reply-To: <h90uf3$bdo$2@news.albasani.net>

Dirk Herrmann wrote:

> I am currently trying to learn about Ada's fixed-point types, and there
> are some points that I couldn't find any statement about, or which I
> simply could not understand.

And, while experimenting and trying out Adam Beneschan's solution for
rounding (thanks for your answer, Alan) I got totally confused because
of the following code (I am using GNAT 4.3.4 with the following
command line options: gnatmake -f -gnatVa -gnata -gnatwadhl.o
-save-temps conversion.adb):  (For your convenience, I added the results
as comments within the code.)

    with Ada.Text_IO;

    procedure Conversion is

       package TIO renames Ada.Text_IO;
       package FIO is new Ada.Text_IO.Float_IO(Float);

       type FpA is delta 0.5 range -10.0 .. +10.0; for FpA'Small use 0.5;
       type FpB is delta 0.4 range -10.0 .. +10.0; for FpB'Small use 0.4;

       function MakeB(F: in Float) return FpB is
       begin
          return FpB(F);
       end MakeB;

       function MakeBFromA(F: in FpA) return FpB is
       begin
          return FpB(F);
       end MakeBFromA;

       function MakeBViaA(F: in Float) return FpB is
       begin
          return FpB(FpA(F));
       end MakeBViaA;

    begin

       FIO.Put(Float(FpA(-1.5))); TIO.Put(" ");             --> -1.50000E+00
       FIO.Put(Float(FpB(-1.5))); TIO.Put(" ");             --> -1.20000E+00
       FIO.Put(Float(FpB(Float(-1.5)))); TIO.Put(" ");      --> -1.20000E+00
       FIO.Put(Float(MakeB(-1.5))); TIO.Put(" ");           --> -1.60000E+00
       FIO.Put(Float(FpB(FpA(-1.5)))); TIO.Put(" ");        --> -1.20000E+00
       FIO.Put(Float(FpB(FpA(Float(-1.5))))); TIO.Put(" "); --> -1.20000E+00
       FIO.Put(Float(MakeBFromA(FpA(-1.5)))); TIO.Put(" "); --> -1.60000E+00
       FIO.Put(Float(MakeBViaA(-1.5))); TIO.Put(" ");       --> -1.60000E+00

    end Conversion;

Is this confusing behaviour allowed?  I will submit a bug report if some 
expert confirms it is a GNAT bug.

Thanks in advance,

Dirk Herrmann
(email address gladly given on request)



  parent reply	other threads:[~2009-09-19 12:41 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-18 21:35 conversions between fixed-point types Dirk Herrmann
2009-09-18 22:42 ` Adam Beneschan
2009-09-19 12:41 ` Dirk Herrmann [this message]
2009-09-19 14:48   ` John B. Matthews
2009-09-20  8:15     ` Dirk Herrmann
2009-09-20 14:22       ` Robert A Duff
2009-09-20 18:55         ` Dirk Herrmann
2009-09-20 20:34           ` Simon Clubley
2009-09-23 20:46             ` Dirk Herrmann
2009-09-27 17:15               ` Simon Clubley
2009-09-27 19:22           ` sjw
2009-09-28 20:18             ` Dirk Herrmann
2009-09-28 18:37           ` Robert A Duff
2009-09-28 20:50             ` Dirk Herrmann
2009-09-20 15:18       ` John B. Matthews
2009-09-20 19:13         ` Dirk Herrmann
2009-09-20 20:09       ` tmoran
2009-09-21 17:24       ` Jeffrey R. Carter
2009-09-23 20:57         ` Dirk Herrmann
2009-09-23 22:28           ` Jeffrey R. Carter
2009-09-24  1:05             ` Adam Beneschan
2009-09-24  3:57               ` Jeffrey R. Carter
2009-09-25  8:47               ` Stuart
2009-09-25 20:41                 ` sjw
2009-09-25 21:58                   ` Jeffrey R. Carter
2009-09-28 13:40                   ` Stuart
2009-09-26 14:43                 ` Dirk Herrmann
2009-09-28 15:15                   ` Adam Beneschan
2009-09-26 14:31               ` Dirk Herrmann
2009-09-19 18:38   ` tmoran
2009-09-20  8:22 ` sjw
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox