From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3f2ed3f93fdb688b X-Google-Attributes: gid103376,public From: JP Thornley Subject: Re: Disturbing float conversions... Date: 2000/05/02 Message-ID: #1/1 X-Deja-AN: 618423417 X-NNTP-Posting-Host: diphi.demon.co.uk:158.152.212.133 References: <8dfm0q$8nr$1@nnrp1.deja.com> <8en7ij$kr7$1@nnrp1.deja.com> X-Trace: news.demon.co.uk 957301397 nnrp-14:19440 NO-IDENT diphi.demon.co.uk:158.152.212.133 MIME-Version: 1.0 Newsgroups: comp.lang.ada X-Complaints-To: abuse@demon.net Date: 2000-05-02T00:00:00+00:00 List-Id: In article <8en7ij$kr7$1@nnrp1.deja.com>, jboulais@my-deja.com writes >I'm seeing something similar, but perhaps a little more disturbing >(Gnat 3.11p and WinNT 4.0). With Gnat 3.11p and Win98SE on a PIII the answers look a lot more like you would expect: > >I've got the following types defined: > > type Long_Float_Type is digits 8 range -32768.000 .. 32767.000 ; > > subtype Angle_Type is Long_Float_Type range -180.00000 .. 179.99451 ; > >I find that when I do a 'Image on the 'First and 'Last of Angle_Type, I >get -1.7999872E+02 and 1.7999872E+02 respectively. I get: -1.8000000E+02 1.7999451E+02 >If I convert to a long_float (Ada standard, not Long_Float_Type) I get >-1.80000000000000E+02 and 1.79994510000127E+02 respectively, which is >closer, but the 'Last is a little bigger than I defined it to. I get: -1.80000000000000E+02 1.79994510000000E+02 But, of course, 179.99451 cannot be represented *exactly* in any binary floating point value (the fractional part doesn't end in a decimal '5'). >If I instantiate Text_IO.Float_IO with Angle_Type, I get -204.7 and >204.7, which really blows me away. now that is bizarre, I get: -1.8000000E+02 1.7999451E+02 Phil Thornley My code is: with Ada.Text_IO; procedure Float_Values is type Long_Float_Type is digits 8 range -32768.000 .. 32767.000 ; subtype Angle_Type is Long_Float_Type range -180.00000 .. 179.99451 ; package AT_IO is new Ada.Text_IO.Float_IO(Angle_Type); begin Ada.Text_IO.Put_Line(Long_Float_Type'Image(Angle_Type'First)); Ada.Text_IO.Put_Line(Long_Float_Type'Image(Angle_Type'Last)); Ada.Text_IO.Put_Line(Long_Float'Image(Long_Float(Angle_Type'First))); Ada.Text_IO.Put_Line(Long_Float'Image(Long_Float(Angle_Type'Last))); AT_IO.Put(Angle_Type'First); Ada.Text_IO.New_Line; AT_IO.Put(Angle_Type'Last); Ada.Text_IO.New_Line; end Float_Values; -- JP Thornley