How can I get the minimum and maximum exponent for 32- and 64-bit real numbers? I am doing some work to avoid underflows and overflows and would need to know those numbers.
I would also need the base for floating point numbers.
Is it possible in fortran to get the equivalent of ilmach
?
The function
range()
returns the range of exponents. The intrinsic functionhuge()
returns the maximum allowable number for a given numeric kind. From that you can see the exponent too by employing a logarithm. See alsoselected_real_kind()
.The base for gfortran and other normal compilers is 2, but you can test it using
radix()
. They may be some base 10 kinds in the future.In the same manual I linked you will find other useful intrinsics like
tiny(), precision(), epsilon(), spacing()
, you can follow the links in "See also:".For non-zero reals, the numeric model looks like
s*b^e*\sum_{k=1}^{p}f_k*b^{-k}
.To get the value of the base
b
useradix()
. The minimum and maximum values of the exponente
can be found withexponent
combined withtiny
andhuge
.