From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,df90a4053dcaf2ca X-Google-Attributes: gid103376,public From: stt@houdini.camb.inmet.com (Tucker Taft) Subject: Re: Exception on System.Max_Digits Date: 1998/01/30 Message-ID: #1/1 X-Deja-AN: 320671359 Sender: news@inmet.camb.inmet.com (USENET news) X-Nntp-Posting-Host: houdini.camb.inmet.com References: <34D20EC6.55DD@nospam.lmco.com> Organization: Intermetrics, Inc. Newsgroups: comp.lang.ada Date: 1998-01-30T00:00:00+00:00 List-Id: 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