comp.lang.ada
 help / color / mirror / Atom feed
* Help with fixed types...insufficient model numbers?
@ 1997-04-01  0:00 John Gluth
  1997-04-01  0:00 ` john schneider
  1997-04-01  0:00 ` Robert Dewar
  0 siblings, 2 replies; 4+ messages in thread
From: John Gluth @ 1997-04-01  0:00 UTC (permalink / raw)



Can somebody help me understand this model number thing?

I'm using the Rational Apex environment and compiling for 
a PowerPC 603e.

Basic problem:

I've got a 64 bit timer (running at 10 MHz)
I don't need 64 bits of resolution (1 ms is adequate).

I originally planned to use 32 bits of the timer, shifting left 
8 bits, leaving me with LSB = 25.6 microseconds, and a rollover 
time of around 8 hours.

So I tried doing this:

Time_LSB : constant := 0.0000256;

type Time_Type is delta Time_LSB range 0.0 .. 2.0**31 - 1.0;
for Time_Type'Size use 32;
for Time_Type'Small use Time_LSB;

This leads to a complaint from the compiler along the lines of 
'insufficient model numbers'

I did a little more research.  SAFE_SMALL is defined as 1.000000000E-04

As I understand it, SAFE_SMALL would indicate the smallest value for 
for 'Small that would give me enough model numbers to get the full
range of values (-2.0**31 .. 2.0**31 -1.0)...true?

I did a little experimenting, and found that if I use:

Time_LSB : constant := 1.0;     => No problem with 0..2.0 ** 31 - 1.0
Time_LSB : constant := 0.0001;  => Insufficient model numbers
                                   (even using 0..2.0**30, 2.0**29, etc.)
Time_LSB : constant := 0.1;     => Still insufficient model numbers
                                   down to 2.0**29, etc.

How does one determine what the maximum allowable range is?

There is an attribute LAST, which is listed as 214748.3647
Is this my upper limit?  If so, why?

What's the largets upper bound I can get with a 32 bit fixed number and
an LSB (Small) of around 1E-3?

Thanks,

John




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Help with fixed types...insufficient model numbers?
  1997-04-01  0:00 Help with fixed types...insufficient model numbers? John Gluth
  1997-04-01  0:00 ` john schneider
@ 1997-04-01  0:00 ` Robert Dewar
  1 sibling, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1997-04-01  0:00 UTC (permalink / raw)



John Gluth asks about

<<Time_LSB : constant := 0.0000256;

type Time_Type is delta Time_LSB range 0.0 .. 2.0**31 - 1.0;
for Time_Type'Size use 32;
for Time_Type'Small use Time_LSB;>>

There is no model number subtlety here, just a plain obviously wrong
declaration. 32 bits would be enough to fit the given range (just, with
one bit to spare) if the delta were 1.0. Obviously with a delta of
0.0000256 you need far more bits. If you feed this to GNAT, you get:


     1. package j is
     2.    Time_LSB : constant := 0.0000256;
     3.    type Time_Type is delta Time_LSB range 0.0 .. 2.0**31 - 1.0;
     4.    for Time_Type'Size use 32;
           |
        >>> size given (32) for type "Time_Type" too small, minimum is 47

     5.    for Time_Type'Small use Time_LSB;
     6. end;

which seems obviously right for storing numbers in the range you give
with the least significant bit you give. It is not clear why this is
puzzling, so I can't figure out more to say ...





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Help with fixed types...insufficient model numbers?
  1997-04-01  0:00 Help with fixed types...insufficient model numbers? John Gluth
@ 1997-04-01  0:00 ` john schneider
  1997-04-02  0:00   ` Robert Dewar
  1997-04-01  0:00 ` Robert Dewar
  1 sibling, 1 reply; 4+ messages in thread
From: john schneider @ 1997-04-01  0:00 UTC (permalink / raw)



John,
  Re-check what you are asking for --- your example, specifies a
range of 0.0 .. 2.0**31 - 1.0.  This range already requires 30 bits
to store just integer values.  Your delta of 0.0000256 asks for an
additional 39000+ values per integer!  What you asked for obviously
won't fit in a 32-bit quantity.

First, verify that your compiler really allows you to specify a
type'SMALL that is not a power of two -- some (i.e. mine) will not.
Generally, the compiler will reserve for the fractional portion of
a value, as many bits as is needed to store the largest power of 2
which is smaller than the "delta" you specify.  Your request
for 1E-3, or 1/1000. Means that the compiler will use 1/1024, which
requires 10 bits, leaving 22 bits to represent the range of your
value and the sign of the number (remember, base types need symmetry
around 0, even when you are not using negatives).  Therefore, you
should be able to specify a range of -2.0**21 .. 2.0**21 - 1.0.

John Gluth wrote:
> 
> Can somebody help me understand this model number thing?
> 
> I'm using the Rational Apex environment and compiling for
> a PowerPC 603e.
> 
> Basic problem:
> 
> I've got a 64 bit timer (running at 10 MHz)
> I don't need 64 bits of resolution (1 ms is adequate).
> 
> I originally planned to use 32 bits of the timer, shifting left
> 8 bits, leaving me with LSB = 25.6 microseconds, and a rollover
> time of around 8 hours.
> 
> So I tried doing this:
> 
> Time_LSB : constant := 0.0000256;
> 
> type Time_Type is delta Time_LSB range 0.0 .. 2.0**31 - 1.0;
> for Time_Type'Size use 32;
> for Time_Type'Small use Time_LSB;
> 
> This leads to a complaint from the compiler along the lines of
> 'insufficient model numbers'
> 
> I did a little more research.  SAFE_SMALL is defined as 1.000000000E-04
> 
> As I understand it, SAFE_SMALL would indicate the smallest value for
> for 'Small that would give me enough model numbers to get the full
> range of values (-2.0**31 .. 2.0**31 -1.0)...true?
> 
> I did a little experimenting, and found that if I use:
> 
> Time_LSB : constant := 1.0;     => No problem with 0..2.0 ** 31 - 1.0
> Time_LSB : constant := 0.0001;  => Insufficient model numbers
>                                    (even using 0..2.0**30, 2.0**29, etc.)
> Time_LSB : constant := 0.1;     => Still insufficient model numbers
>                                    down to 2.0**29, etc.
> 
> How does one determine what the maximum allowable range is?
> 
> There is an attribute LAST, which is listed as 214748.3647
> Is this my upper limit?  If so, why?
> 
> What's the largets upper bound I can get with a 32 bit fixed number and
> an LSB (Small) of around 1E-3?
> 
> Thanks,
> 
> John


John Schneider
j-schneider@ti.com

The opinions are mine, but you are welcome to share them.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Help with fixed types...insufficient model numbers?
  1997-04-01  0:00 ` john schneider
@ 1997-04-02  0:00   ` Robert Dewar
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1997-04-02  0:00 UTC (permalink / raw)



John said

<,First, verify that your compiler really allows you to specify a
type'SMALL that is not a power of two -- some (i.e. mine) will not.>>

I am surprised that there are compilers that are that limited for fixed
point, but in any case no "verification" is required. It is true that
a compiler may reject small's that are not powers of 2, but it is
MANDATORY that they do this at compile time, treating the offending
declarations as illegal. A compiler that silently ignord small
specifications would be non-conforming (and I would consider that
a pretty serious bug!)






^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1997-04-02  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-04-01  0:00 Help with fixed types...insufficient model numbers? John Gluth
1997-04-01  0:00 ` john schneider
1997-04-02  0:00   ` Robert Dewar
1997-04-01  0:00 ` Robert Dewar

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