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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,388fc53f584bd695 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!feeder.news-service.com!85.214.198.2.MISMATCH!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.ada Subject: Re: Fixed point constants issue Date: Tue, 14 Sep 2010 12:44:29 -0700 Organization: None to speak of Message-ID: References: <1f0l0baynq1x7$.phl9cqpwcr37.dlg@40tude.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Tue, 14 Sep 2010 19:44:32 +0000 (UTC) Injection-Info: mx01.eternal-september.org; posting-host="9nFTuw1iclElqUG5+//YDQ"; logging-data="31446"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19viFtd/RGNX39DLBbMTj/r" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:KN3usmsRUK7jVwkVmh1QXoK2qu0= sha1:Fxl5Wo6n6jJN0VAIPsYI3PxttOQ= Xref: g2news1.google.com comp.lang.ada:14082 Date: 2010-09-14T12:44:29-07:00 List-Id: "Dmitry A. Kazakov" writes: > On Mon, 13 Sep 2010 19:27:30 +0200, Vinzent Hoefler wrote: >> Is this a GNAT bug or am I just stupid? >> >> Suppose we have a fixed point type (with a rather large delta): >> >> -- 8< -- >> with Ada.Text_IO; use Ada.Text_IO; >> >> procedure Fixed_Point >> is >> FEET_PER_METER : constant := 0.3048; >> HEIGHT : constant := 10; -- Feet >> >> type Altitude is delta (2.0**15 / 50_000.0) range 0.0 .. 50_000.0; > > [...] >> Can anyone shed some light on this? This has driven us crazy for weeks now. >> >> [1] Of course, "Altitude'(HEIGHT * FEET_PER_METER)" yields "0.0" again. >> At least this is consistent with my understanding so far. > > Hmm, what did you expect? 0.3048 (FEET_PER_METER) is 0 when Altitude. That > is because 2.0**15/50_000.0=0.65536 > 0.3048. Close, but actually it's because 2.0**15/50_000.0=0.65536 > 0.5. Altitude'Delta = 0.65536. Altitude'Small = 0.5. If you want the 'Small to be the same as the 'Delta, you have to specify it (or use a power of 2.0). -- Keith Thompson (The_Other_Keith) kst-u@mib.org Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"