comp.lang.ada
 help / color / mirror / Atom feed
From: "Peter C. Chapin" <chapinp@acm.org>
Subject: Re: Question about ordinary fixed point types.
Date: Mon, 16 Aug 2010 07:31:48 -0400
Date: 2010-08-16T07:31:48-04:00	[thread overview]
Message-ID: <4c6921c2$0$2385$4d3efbfe@news.sover.net> (raw)
In-Reply-To: <i4adop$2dtr$1@adenine.netfront.net>

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



  parent reply	other threads:[~2010-08-16 11:31 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-15 21:43 Question about ordinary fixed point types Peter C. Chapin
2010-08-15 21:55 ` Shark8
2010-08-16  0:46   ` Peter C. Chapin
2010-08-16  4:13     ` Jeffrey Carter
2010-08-16  8:57       ` Simon Wright
2010-08-15 22:08 ` Yannick Duchêne (Hibou57)
2010-08-16  1:03   ` Peter C. Chapin
2010-08-16  4:11     ` Jeffrey Carter
2010-08-16 10:03       ` Ludovic Brenta
2010-08-17 14:35         ` sjw
2010-08-17 15:51           ` Ludovic Brenta
2010-08-16 11:31       ` Peter C. Chapin [this message]
2010-08-16  9:23     ` Simon Wright
2010-08-16 15:47       ` Simon Wright
2010-08-17 14:37       ` sjw
2010-08-16 11:02 ` Stephen Leake
2010-08-16 11:29   ` Peter C. Chapin
2010-08-16 12:53     ` Dmitry A. Kazakov
2010-08-16 20:28       ` Peter C. Chapin
2010-08-16 20:58         ` Adam Beneschan
2010-08-16 13:01     ` Dmitry A. Kazakov
2010-08-16 14:28     ` Robert A Duff
2010-08-16 20:31       ` Peter C. Chapin
2010-08-16 23:01         ` Robert A Duff
2010-08-16 23:17           ` Peter C. Chapin
2010-08-17  0:56             ` Robert A Duff
2010-08-17  2:03     ` Stephen Leake
2010-08-20  1:21 ` Yannick Duchêne (Hibou57)
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox