SYSTEM.MAX_DIGITS Insufficient for Portability 84-10-01 AI-00291/00 1
!standard 13.07 (03) 84-10-01 AI-00291/00
!class study 84-10-01 (provisional classification)
!status received 84-10-01
!topic SYSTEM.MAX_DIGITS Insufficient for Portability
!summary 84-10-01
!question 84-10-01
!recommendation 84-10-01
!wording 84-10-01
!discussion 84-10-01
!appendix 84-10-01
******************************************************************************
!section 13.07 (03) Software Leverage, Inc. 84-01-30 83-00433
!version 1983
!topic SYSTEM.MAX_DIGITS Insufficient for Portability
There seems to be no way to write a generic package which works for all
floating point subtypes without (1) simulating floating point "by hand", or (2)
making assumptions about the particular implementation. This problem was found
while considering the implementation of TEXT_IO.FLOAT_IO.
The problem is that the predefined floating point type with the greatest
precision (assuming there is only one!) isn't guaranteed to also have the
largest exponent range for its safe numbers. Thus declaring
type LONGEST_FLOAT is digits SYSTEM.MAX_DIGITS;
is not sufficient to yield a floating point type whose safe numbers are certain
to include those of some generic formal type T.
It should be observed that T cannot itself be used as the type of objects
within the generic unit, since the range of T may not include important values
like 0.0. Nor can T'BASE be used as the type of declared objects, because of
3.3.3(9). Finally, a trick like
type T_BASE_COPY is digits T'DIGITS
range -T'BASE'SAFE_LARGE..T'BASE'SAFE_LARGE;
fails because attributes of T aren't static. (The above wouldn't always be a
copy, since T'BASE'FIRST and T'BASE'LAST might not be safe numbers, but it
would be good enough.)
The minimum fix to this situation seems to be to invent a named number
SYSTEM.MAX_SAFE_EMAX and demand that (1) T'SAFE_EMAX never exceeds this value
for any floating point type T, (2) there is some predefined floating point type
SYSTEM.MAX_DIGITS Insufficient for Portability 84-10-01 AI-00291/00 2
which achieves both the maximum precision and the maximum exponent range for
safe numbers simultaneously. (It seems likely that for most systems, the
highest precision floating point type will have the largest exponent range
anyway. For other systems, requiring that a few floating point types claim
less exponent range than they "actually" have seems in the same Ada spirit of
portability as, say, the demand that T'DIGITS guarantees both a precision and
an exponent range.)
Assuming that there isn't a programming trick we have failed to find which
circumvents the problems mentioned above, we recommend that the above change or
something similar be put into package SYSTEM for the next version of Ada.