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,65b3f028266fd999 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx01.iad01.newshosting.com!newshosting.com!novia!news-out.readnews.com!postnews3.readnews.com!not-for-mail Date: Mon, 16 Aug 2010 07:31:48 -0400 From: "Peter C. Chapin" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.8) Gecko/20100802 Lightning/1.0b2 Thunderbird/3.1.2 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Question about ordinary fixed point types. References: <4c685fac$0$2373$4d3efbfe@news.sover.net> <4c688e67$0$2389$4d3efbfe@news.sover.net> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Message-ID: <4c6921c2$0$2385$4d3efbfe@news.sover.net> Organization: SoVerNet (sover.net) NNTP-Posting-Host: 6f58482c.news.sover.net X-Trace: DXC=kXWcfMLgk[>;9JBfm>n X-Complaints-To: abuse@sover.net Xref: g2news1.google.com comp.lang.ada:13400 Date: 2010-08-16T07:31:48-04:00 List-Id: On 2010-08-16 00:11, Jeffrey Carter wrote: > Consider this example, which I 1st encountered in 1984: > > with Ada.Text_IO; > > procedure Fixed_Test is > type Money is delta 0.01 range -100.0 .. 100.0; > > Cent : constant Money := Money'Delta; > > Change : Money := 0.0; > begin -- Fixed_Test > Sum : for I in 1 .. 5 loop > Change := Change + Cent; > end loop Sum; > > Ada.Text_IO.Put_Line (Item => Money'Image (Change) ); > end Fixed_Test; > > Typically, the 'Small will be 2#0.000_000_1#, and the program will > output 0.04. The program adds the machine number closest to 'Delta > (which is 'Small) each time, not 'Delta, so there's no "snapping" taking > place, except in the conversion of 0.01 to a machine number of type Money. The use of Small instead of Delta is the "snapping" I was talking about. That is, despite the fact that you ask for Money'Delta you end up advancing Change by Money'Small in your loop. In my case advancing by Small is the effect I'm after so my earlier loop where I was adding in Delta each time would have probably still worked reliably. Peter