tedg@apollo.HP.COM (Ted Grzesik) (06/13/91)
I have a question regarding constraint checks of floating point assignments. The LRM (3.5.7) does not make it clear to me whether my compiler is failing to give a CONSTRAINT_ERROR in the following situation: Note: some code not shown. with text_io; procedure float_test is package short_float_io is new text_io.float_io ( short_float ); package long_float_io is new text_io.float_io (float ); package int_io is new text_io.integer_io (integer); value, value1, value2 : short_float; lvalue, lvalue1, lvalue2 : float; begin . . . value := short_float(-9.0E-150); text_io.put( "The value of -9.0E-150 is " ); short_float_io.put ( value ); text_io.new_line; value := short_float(-9.0E-38); value1 := short_float(9.0E-38); value2 := value * value1; text_io.put ( "The value of -9.0E-37 * 9.0E-37 is "); short_float_io.put( value2 ); text_io.new_line; lvalue := float(-9.0E-500); text_io.put ( " The value of -9.0E-500 is " ); long_float_io.put ( lvalue ); text_io.new_line; lvalue := float(-9.0E-500); lvalue1 := float(9.0E-500); lvalue2 := lvalue * lvalue1; text_io.put ( " The value of -9.0E-500 * -9.0E-500 is " ); long_float_io.put( lvalue2 ); text_io.new_line; end float_test; Execution results: Attributes for short_float: DIGITS: 6 MANTISSA: 21 EPSILON: 9.53674316406250E-07 EMAX: 84 SMALL: 2.58493941422821E-26 LARGE: 1.93428038904620E+25 SAFE_EMAX: 126 SAFE_SMALL: 5.87747175411144E-39 SAFE_LARGE: 8.50705511654154E+37 Attributes for float: DIGITS: 15 MANTISSA: 51 EPSILON: 8.88178419700125E-16 EMAX: 204 SMALL: 1.94469227433161E-62 LARGE: 2.57110087081438E+61 SAFE_EMAX: 1022 SAFE_SMALL: 1.11253692925360E-308 SAFE_LARGE: 4.49423283715579E+307 The value of -9.0E-150 is 0.00000E+00 The value of -9.0E-37 * 9.0E-37 is 0.00000E+00 The value of -9.0E-500 is 0.00000000000000E+00 The value of -9.0E-500 * -9.0E-500 is 0.00000000000000E+00 -- Ted Grzesik Massachusetts Language Lab Hewlett-Packard Company tedg@apollo.hp.com Chelmsford, MA (508) 256-6600 x5959 "Civilization is the limitless multiplication of unnecessary necessities." -- Mark Twain (Samuel Clemens)
eachus@largo.mitre.org (Robert I. Eachus) (06/13/91)
In article <1991Jun12.190054.27094@apollo.hp.com> tedg@apollo.HP.COM (Ted Grzesik) writes:
I have a question regarding constraint checks of floating point assignments.
The LRM (3.5.7) does not make it clear to me whether my compiler is failing to give a CONSTRAINT_ERROR in the following situation...
Note: All code not shown.
First of all, I assume the reference was to 4.5.7. But under no
circumstances should this program raise CONSTRAINT_ERROR. You seem to
believe that there should be an underflow check, but the Ada floating
point model has no such concept. (All results which might be
considered as underflow are represented by ANY value in a range
bounded inclusively by zero and the smallest positive or negative
safe number.)
Where underflow and reduced acuracy are concerns in Ada, you either
have to define your own floating-point operators (which for example
would raise UNDERFLOW_ERROR), or use scaling and fixed point.
--
Robert I. Eachus
with STANDARD_DISCLAIMER;
use STANDARD_DISCLAIMER;
function MESSAGE (TEXT: in CLEVER_IDEAS) return BETTER_IDEAS is...
stt@inmet.inmet.com (06/15/91)
Re: float constraint checks Underflow is never an error in Ada; instead it yields 0.0. This is a ramification of the model-number accuracy rules. The Ada Reference Manual doesn't come out and say "no exception on underflow" (at least I couldn't find it), but that is the case. S. Tucker Taft Intermetrics, Inc. Cambridge, MA 02138