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 21:03:07 -0400
Date: 2010-08-15T21:03:07-04:00	[thread overview]
Message-ID: <4c688e67$0$2389$4d3efbfe@news.sover.net> (raw)
In-Reply-To: <op.vhh2f5neule2fv@garhos>

On 2010-08-15 18:08, Yannick Duchêne (Hibou57) wrote:

> Hi Peter, nice to see you again,

Hi!

> What do you mean with “to the next machine number in the type” ? That
> this may not advance in some case ?

The manual talks about machine numbers which, as I understand it, are
the mathematical values which are precisely represented by the fixed
point type. In my case they are the multiples of 2**(-11).

In my first (less informed?) attempt I used Angle_Type'Delta like this:

Angle := Angle + Angle_Type'Delta;

However, the distance between the represented values (the "machine
numbers") is not Delta, but rather Small. I suppose it wouldn't matter
much because the resulting value would "snap to" a machine number when
assigned to Angle. Well, I think.

> If the matter is the precise exploration of a precise set of points in a
> range, I may have a silly suggestion (silly in some sense, while not so
> much in some others) : why not use an array of predefined points ? Here,
> you would have an array of 12566 points. Ok, this may seems a big array,
> some design for hight efficiency.

I need to do real number computations on a microcontroller without a
floating point unit. I believe the various numeric quantities that I
need can be normalized into fairly narrow ranges so it seemed to me that
this is a perfect application of fixed point types. The compiler stores
the numbers as integers representing the appropriate multiple of Small.

I'm not using GNAT on the microcontroller but if the Ada compiler I am
using does the same thing as GNAT it will be able to fit Angle_Type as
it is currently defined into a 16 bit word and compute with it using
integer instructions. In my environment that is essential.

At the moment I'm looking at implementing some basic trig functions such
as Sine and Cosine taking Angle_Type parameters. My test program
compares the computed results against the much higher precision values
from GNAT's normal numeric library. I can thus assess the overall
accuracy of my implementation. I want to check every possible Angle_Type
value to be sure there are no surprises. For example right now I get
Constraint_Error when I attempt to compute the Sine of Angle_Type'First.
This is apparently because Angle_Type'First is actually slightly less
than -Pi and my simplistic implementation can't cope with that.

Peter

BTW, I will probably need a smaller delta than 0.0005 eventually (I
think). But I imagine changing that will be easy enough once I
understand what I'm doing. Alas, using too small a delta will probably
force the compiler to use 32 bits to store an Angle_Type value and
that's an undesirable thing on my machine.



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