I would like to know how fortran 95 (f95) would convert a double precision (DP) with an exponent larger than can be held in a single precision (SP) exponent.
So say I have some DP number with an exponent larger than that which can be store into the SP data type. Does it just max out the exponent and chop the mantissa and store it that way or does something else happen.
If this is correct, then does that mean that anytime the exponent is too large going from DP to SP, will I get either + or - Infinity (if the mantissa for the DP had zeros in the first 8 bits) and NaN (if any of the first 8 bits in the mantissa were 1)?
Thank you very much for your help!!!!
Yes, if you attempt to store a double precision variable a
into a single precision variable b
, while a
is not in the range of [-HUGE(b),HUGE(b)]
, b
will become +Inf
or -Inf
, depending on the sign of a
.
This is indeed a desired behavior - a feature that captures floating overflows and helps debugging tremendously.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With