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!news3.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: Sun, 20 Sep 2009 11:18:53 -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:oOUeQzLyLZYA9hZu9dz13DCvhZU= User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: g2news2.google.com comp.lang.ada:8405 Date: 2009-09-20T11:18:53-04:00 List-Id: In article , Dirk Herrmann wrote: > Dirk Herrmann wrote: > >> 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. > > John B. Matthews wrote: > > I'm no expert, and I had some trouble following the conversions in > > your example. [...] > > Sorry, I should have given more details about why I am confused. Not at all. My confusion arises from my own poor understanding of how to apply the rules to the various conversions. > In particular I am disturbed by the fact that the following two lines produce > different results with GNAT, as has been confirmed for GNAT 3.15p (thanks, > tmoran): > FIO.Put(Float(FpB(Float(-1.5)))); TIO.Put(" "); --> -1.20000E+00 > FIO.Put(Float(MakeB(-1.5))); TIO.Put(" "); --> -1.60000E+00 > In the first line, the conversion to FpB is done from a Float value, > which is a direct cast from -1.5. In the second line, the conversion > to FpB is also done from a Float value, but in this case -1.5 is > passed as a Float argument to MakeB. What I don't understand is, why > it should make a difference whether I cast -1.5 to Float and then > convert it to FpB compared to the situation where -1.5 is converted > to a Float argument, which is then converted to FpB. I see what you mean. Here's my understanding: The Ada Reference Manual [1], section 3.6(32) on numeric type conversion refers to section G.2.1 and G.2.3 for floating- and fixed-point arithmetic, respectively. The value -1.5 is exactly representable as type Float, but not as type FpB. The conversion to FpB is governed by G.2.3(10), so both -1.2 and -1.6 are in the close result set. Because FpB is an ordinary fixed point type, rather than a decimal fixed point type, there's no requirement to prefer one element of the result set over another. The conversion back to Float is discussed in G.2.1(10). Because small is not a power of T'Machine_Radix, the result is implementation defined. I'm not sure if GNAT fully implements Annex G, and I may be overlooking something obvious. >From another perspective, I'm curious to know why the conversions are needed. [1] [...] -- John B. Matthews trashgod at gmail dot com