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

* Re: Fixed Point Range
  1997-10-25  0:00 Fixed Point Range Matthew Heaney
@ 1997-10-26  0:00 ` Robert Dewar
  1997-11-05  0:00   ` Mark Lusti
  0 siblings, 1 reply; 4+ messages in thread
From: Robert Dewar @ 1997-10-26  0:00 UTC (permalink / raw)



Matthew Heany says

  <<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 >>

The above output is correct, i.e. it is consistent with one of
several possible sets of output permitted by the RM in this case.

  <<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?>>

You read the RM wrong, it explicitly permits 255.0 in this case, with
exactly this situation in mind.

  <<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.>>

Your output is correct

Incidentally, I suggest that if you are interested in finding out more
about fixed point, you will find it helpful to read the special issue
report I did for the SEI on this subject during the Ada 9x development.





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

* Re: Fixed Point Range
  1997-11-05  0:00   ` Mark Lusti
@ 1997-11-04  0:00     ` Matthew Heaney
  0 siblings, 0 replies; 4+ messages in thread
From: Matthew Heaney @ 1997-11-04  0:00 UTC (permalink / raw)



In article <345FB2F3.32566E55@bluewin.ch>, mark.lusti@bluewin.ch wrote:

>Robert Dewar wrote:
>
>> Incidentally, I suggest that if you are interested in finding out more
>> about fixed point, you will find it helpful to read the special issue
>> report I did for the SEI on this subject during the Ada 9x development.
>
>Could you please name the link to the document or sei document number.

The Fixed Point Facility In Ada
Tech Report Special Report Feb 90
SEI-90-SR-2
Robert Dewar

Robert also wrote

Shared Variables and Ada 9X Issues
Special Report Jan 90
SEI-90-SR-1

You have to order it from NIST (I think); I haven't done so yet, but I'll
post the details once I do.

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




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

* Re: Fixed Point Range
  1997-10-26  0:00 ` Robert Dewar
@ 1997-11-05  0:00   ` Mark Lusti
  1997-11-04  0:00     ` Matthew Heaney
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Lusti @ 1997-11-05  0:00 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1175 bytes --]


This is a multi-part message in MIME format.
--------------116A39E6493084ACD58B8598
Content-Type: text/plain; charset=us-ascii
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Transfer-Encoding: 7bit

Robert Dewar wrote:

> Incidentally, I suggest that if you are interested in finding out more
> about fixed point, you will find it helpful to read the special issue
> report I did for the SEI on this subject during the Ada 9x development.

Could you please name the link to the document or sei document number.

Thanks

Mark Lusti


--------------116A39E6493084ACD58B8598
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Mark Lusti
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Mark Lusti
n:              Lusti;Mark
org:            @Home
adr:            Mattackerstrasse 6;;;Z�rich;;CH-8052 ;Switzerland
email;internet: mark.lusti@bluewin.ch
tel;work:       +41-1-316 2967
tel;home:       +41-1-301 0842
x-mozilla-cpt:  ;0
x-mozilla-html: TRUE
end:            vcard


--------------116A39E6493084ACD58B8598--





^ 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