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: a07f3367d7,6fabd104d18f3943 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!aioe.org!nospam From: "John B. Matthews" Newsgroups: comp.lang.ada Subject: Re: conversions between fixed-point types Date: Sat, 19 Sep 2009 10:48:12 -0400 Organization: The Wasteland Message-ID: References: NNTP-Posting-Host: LQJtZWzu+iKlBROuDg+IUg.user.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org X-Notice: Filtered by postfilter v. 0.8.0 Cancel-Lock: sha1:jOoCHpIN5XWNtxGAdM5zYcuaOfk= User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: g2news2.google.com comp.lang.ada:8394 Date: 2009-09-19T10:48:12-04:00 List-Id: In article , Dirk Herrmann wrote: > 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): [...] > Is this confusing behaviour allowed? I will submit a bug report if > some expert confirms it is a GNAT bug. I'm no expert, and I had some trouble following the conversions in your example. I tried a more direct test, and I don't see anything unusual; rounding appears consistent. Rounding away from zero is required for decimal fixed point types; but rounding toward zero is permitted for ordinary fixed point types such as FpA and FpB. 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; package AIO is new Ada.Text_IO.Fixed_IO(FpA); package BIO is new Ada.Text_IO.Fixed_IO(FpB); V : Float := -2.0; begin while V < 0.0 loop FIO.Put(V, 1, 1, 0); TIO.Put(" "); AIO.Put(FpA(V)); TIO.Put(" "); BIO.Put(FpB(V)); TIO.New_Line; V := V + 0.1; end loop; end Conversion; $ make run Darwin: gcc 4.3.4 gnatmake conversion -cargs -O2 -bargs -shared -largs -dead_strip gcc -c -O2 conversion.adb gnatbind -shared -x conversion.ali gnatlink conversion.ali -shared-libgcc -dead_strip ./conversion -2.0 -2.0 -2.0 -1.9 -2.0 -2.0 -1.8 -2.0 -1.6 -1.7 -1.5 -1.6 -1.6 -1.5 -1.6 -1.5 -1.5 -1.6 -1.4 -1.5 -1.2 -1.3 -1.5 -1.2 -1.2 -1.0 -1.2 -1.1 -1.0 -1.2 -1.0 -1.0 -0.8 -0.9 -1.0 -0.8 -0.8 -1.0 -0.8 -0.7 -0.5 -0.8 -0.6 -0.5 -0.4 -0.5 -0.5 -0.4 -0.4 -0.5 -0.4 -0.3 -0.5 -0.4 -0.2 0.0 0.0 -0.1 0.0 0.0 -- John B. Matthews trashgod at gmail dot com