comp.lang.ada
 help / color / mirror / Atom feed
* nasty language rules for fixed_type'last
@ 1989-01-27 16:24 linnig
  1989-01-30 15:45 ` Goodenough
  0 siblings, 1 reply; 2+ messages in thread
From: linnig @ 1989-01-27 16:24 UTC (permalink / raw)


I was astonished to learn that it is possible to raise an exception
by using 'FIRST or 'LAST on a fixed point type.  

Apparently, it is possible to specify a fixed point type that cannot
represent 'FIRST or 'LAST. The following is an example:


   1|PROCEDURE fixedtest IS
   2|TYPE f IS DELTA 1.0 RANGE 0.0 .. 32767.9; 
   3|
   4|x: f;
   5|BEGIN
   6| x:= f'last;
           ^1
***  1 Warn 4005: This operation will raise numeric_error at runtime because
***     of arithmetic overflow or because the result is not representable in
***     the target type format 
   7|END;
[TARTAN Ada VMS/1750A, Version V2.05]

The following paragraphs from the Ada LRM (3.5.9 and Appendix A) seems to
allow this behavior:

    "For a fixed point constraint that includes a range constraint, the
    model numbers comprise zero and all multiples of small whose mantissa
    can be expressed using exactly B binary digits, where the value of B is
    chosen as the smallest integer number for which each bound of the
    specified range is either a model number or lies at most small distant
    from a model number."

    "P'FIRST      For a prefix P that denotes a scalar type, or  a  subtype
                  of a scalar type:
                  Yields the lower bound of P.  The value of this attribute
                  has the same type as P.  (See 3.5.)"

For the language to allow 'FIRST and 'LAST to raise exceptions seems
very dangerous.  At least (for this example) it can be caught at compile
time.

	Mike Linnig,
	Texas Instruments

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

end of thread, other threads:[~1989-01-30 15:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1989-01-27 16:24 nasty language rules for fixed_type'last linnig
1989-01-30 15:45 ` Goodenough

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