comp.lang.ada
 help / color / mirror / Atom feed
* Fixed Point Range
@ 1997-10-25  0:00 Matthew Heaney
  1997-10-26  0:00 ` Robert Dewar
  0 siblings, 1 reply; 4+ messages in thread
From: Matthew Heaney @ 1997-10-25  0:00 UTC (permalink / raw)



A fixed point type declaration introduces a type and a first named subtype. 
According to the RM (or, at least my reading of the RM), the range for the
first subtype is chosen as the value closer to zero of, the corresponding
value of the base range, or, the value of the expression implicitly
converted to the type.

Consider this type:

   type Fixed is delta 1.0 range 0.0 .. 256.0;
   for Fixed'Small use 1.0;

In the code example below, I print out the values of Fixed'Last and
Fixed'Base'Last.  The output is:

T'Size:  8
T'Base'Size:  16

T'First:  0.0
T'Last:  255.0

T'Base'First: -32768.0
T'Base'Last:  32767.0

My question is this.  I interpret the RM to mean that Fixed'Last is the
smaller of 256.0 (the expression specified the type declaration) and
32767.0 (the value of Fixed'Base'Last).  Yet the value of Fixed'Last is
255.0.  Why?

The RM says that the expression for the upper bound is "implicitly
converted" to the type.  Does this mean that the value of the expression
256.0 can be implicitly converted to the value 255.0?

I would understand if the base range were -256.0 .. 255.0, then the value
of Fixed'Last would make sense.  Yet, the output is telling me the base
range is much larger than that, so why isn't the value 256.0 used as
Fixed'Last?

Or perhaps I printed out the value of the base range incorrectly.  Is there
a preferred method to Fixed'Base'Image (Fixed'Base'Last)?  Maybe the base
range really is -256.0 .. 255.0, and just my output is bad.


-- STX
with Ada.Text_IO; use Ada.Text_IO;
procedure Test_Fixed is

   type Fixed is delta 1.0 range 0.0 .. 256.0;
   for Fixed'Small use 1.0;

begin

   Put ("T'Size: "); 
   Put (Integer'Image (Fixed'Size)); 
   New_Line;

   PUt ("T'Base'Size: "); 
   Put (Integer'Image (Fixed'Base'Size)); 
   New_Line (2);

   Put ("T'First: "); 
   Put (Fixed'Image (Fixed'First)); 
   New_Line;

   Put ("T'Last: "); 
   Put (Fixed'Image (Fixed'Last)); 
   New_Line (2);

   Put ("T'Base'First: "); 
   Put (Fixed'Base'Image (Fixed'Base'First)); 
   New_Line;

   Put ("T'Base'Last: ");
   Put (Fixed'Base'Image (Fixed'Base'Last)); 
   New_Line (2);

end;
--ETX

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-25  0:00 Fixed Point Range Matthew Heaney
1997-10-26  0:00 ` Robert Dewar
1997-11-05  0:00   ` Mark Lusti
1997-11-04  0:00     ` Matthew Heaney

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