comp.lang.ada
 help / color / mirror / Atom feed
From: "Peter C. Chapin" <chapinp@acm.org>
Subject: Re: Question about ordinary fixed point types.
Date: Sun, 15 Aug 2010 20:46:03 -0400
Date: 2010-08-15T20:46:03-04:00	[thread overview]
Message-ID: <4c688a68$0$2376$4d3efbfe@news.sover.net> (raw)
In-Reply-To: <b8a046fa-4c01-4d35-9fbf-c77205669f42@i13g2000yqd.googlegroups.com>

On 2010-08-15 17:55, Shark8 wrote:

>> type Angle_Type is delta 0.0005 range -3.1416 .. 3.1416;
> 
> The first thing I see here is that 0.0005 doesn't evenly divide
> 2*3.1416; is that going to be a problem?

In theory it is not a problem. My reading of the Ada Reference Manual
tells me that the implementation chooses a value of Small (the actual
difference between represented numbers) that is no more than the
specified delta. Note that Small must be a power of 2, but can be
controlled with a representation clause. In my case GNAT appears to be
using 2**(-11) which is 0.0004883. Implementations can choose a smaller
Small if they want.

The values in the type then become all the multiples of Small "between"
the endpoints of the specified range. However, those endpoints are
converted to the nearest multiple of Small (unless they fall exactly
between two multiples in which case the value closer to zero wins). You
can probably tell I've been reading the manual. :)

I'm not sure which multiple of 2**(-11) are involved here exactly but it
appears that the mathematical value of -3.1416 is rounding down...
meaning more negative. I'm not too worried about that right now. I just
wondered how I could visit all the values of the type in a loop.

Probably I should use extra digits in the definition of the range to
communicate my intentions to the compiler more precisely. Thus

type Angle_Type is delta 0.0005 range -3.1415926535 .. 3.1415926535;

That way when the compiler decides how to round the end points of the
range, it will definitely do the right thing.

Peter



  reply	other threads:[~2010-08-16  0:46 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 [this message]
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
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