Floating point data types

Applicable receivers:  All receivers

Floating-point data types are stored in the IEEE SINGLE and DOUBLE precision formats. Both formats have a sign bit field, an exponent field, and a fraction field. The fields represent floating-point numbers in the following manner:

Floating-Point Number = <sign> 1.<fraction field> x 2 (<exponent field> - bias)

  • Sign bit field

    The sign bit field is the most significant bit of the floating-point number. The sign bit is 0 for positive numbers and 1 for negative numbers.

  • Fraction field

    The fraction field contains the fractional part of a normalized number. Normalized numbers are greater than or equal to 1 and less than 2. Since all normalized numbers are of the form 1.XXXXXXXX, the 1 becomes implicit and is not stored in memory. The bits in the fraction field are the bits to the right of the binary point, and they represent negative powers of 2.

    For example:

    0.011 (binary) = 2-2 + 2-3 = 0.25 + 0.125 = 0.375

  • Exponent field

    The exponent field contains a biased exponent; that is, a constant bias is subtracted from the number in the exponent field to yield the actual exponent. (The bias makes negative exponents possible.)

    If both the exponent field and the fraction field are zero, the floating-point number is zero.

  • NaN

    A NaN (Not a Number) is a special value that is used when the result of an operation is undefined. For example, dividing a number by zero results in a NaN.

FLOAT data type

The FLOAT data type is stored in the IEEE single-precision format which is 32 bits long. The most significant bit is the sign bit, the next 8 most significant bits are the exponent field, and the remaining 23 bits are the fraction field. The bias of the exponent is 127. The range of single-precision format values is from 1.18 × 10–38 to 3.4 × 1038. The floating-point number is precise to 6 decimal digits.

DOUBLE

The DOUBLE data type is stored in the IEEE double-precision format which is 64 bits long. The most significant bit is the sign bit, the next 11 most significant bits are the exponent field, and the remaining 52 bits are the fractional field. The bias of the exponent is 1023. The range of single precision format values is from 2.23 x 10–308 to 1.8 x 10308. The floating-point number is precise to 15 decimal digits.