comp.lang.ada
 help / color / mirror / Atom feed
From: stt@houdini.camb.inmet.com (Tucker Taft)
Subject: Re: Exception on System.Max_Digits
Date: 1998/01/30
Date: 1998-01-30T00:00:00+00:00	[thread overview]
Message-ID: <EnM9nz.CKA.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: 34D20EC6.55DD@nospam.lmco.com


K. E. Garlington (Kennie.E.Garlington@nospam.lmco.com) wrote:

: We have a case where two Ada83 compilers provide different results, and
: we are trying to decide which is correct.

: Both compilers have System.Max_Digits = 15. When we use Float_IO
: to read the number

:    -2627.097925618800

: one vendor raises a Constraint_Error, the other doesn't. The vendor
: of the compiler raising the error says that it is because the number
: has too many digits; removing the final zero causes the exception to
: be avoided. The other vendor accepts the number.

: Is either vendor wrong?

The vendor whose compiler raises Constraint_Error is wrong (based
on the information you give above).  You might ask the vendor
to quote chapter and verse of the reference manual to justify
why Constraint_Error is being raised.  I can say fairly
confidently that there is no run-time constraint check in Ada 83 
or Ada 95 that is somehow related to System.Max_Digits.

You are allowed to give as many digits in a real numeral as you want
on input to Float_IO.Get.  The value of Max_Digits is unrelated
to this.  Max_Digits indicates the number of digits of 
precision kept internally in the most precise floating point type.  
The parameter "Width" to Get limits the number of digits that
are looked at, but you should still never get Constraint_Error
due to overrunning the Width.  Float_IO.Get will simply ignore
the extra digits.

The only justification for Constraint_Error would be if the *value* of
the number exceeds the base range of the floating point type.  The
number of digits is irrelevant.  Given the typical algorithm
for converting an external representation for a floating point
number into an internal representation, one might expect
the algorithm to raise Constraint_Error if the number of digits was
so great that the value of the number you get if you ignore the
decimal point (or pretend it is all the way on the right) was
beyond (Long_)Float'Last.  But on a typical IEEE machine, that would be
more like 38 digits.  A smarter algorithm simply ignores
digits after a certain number because they would have no effect on
the final result.

: Also, will System.Max_Digits apply to any floating-point type?

It represents the precision of the most precise floating point type.
It is unrelated to the number of digits allowed on input
to Float_IO.Get.  There should be no practical limit on that.

--
-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Burlington, MA  USA




  reply	other threads:[~1998-01-30  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-01-30  0:00 Exception on System.Max_Digits K. E. Garlington
1998-01-30  0:00 ` Tucker Taft [this message]
1998-02-01  0:00 ` Robert Dewar
1998-02-01  0:00   ` Ken Garlington
  -- strict thread matches above, loose matches on Subject: below --
1998-02-05  0:00 Dan Lehman
1998-02-05  0:00 Dan Lehman
replies disabled

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