Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IEEE 754 double precision to single precision

Tags:

fortran

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!!!!

like image 710
Differintegral Avatar asked Feb 07 '12 04:02

Differintegral


1 Answers

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.

like image 115
milancurcic Avatar answered Oct 23 '22 00:10

milancurcic