Search code examples
floating-pointprecisioncpu-architectureieee-754

How computer stores 0.000000f according to IEEE 754 floating point representation?


As we know that we can represent any floating number in IEEE 754 floating point representation.But, in all the floating number we get something like 1.(some mantissa) * 2^(some exponent) where 1 is always fixed at first position and thus we assume it while converting back any IEEE 754 floating point number to decimal number.But what will we assume in case of 0.000000f as in that case we can not represent the number in 1.(some mantissa) * 2^(some Exponent) as it can never have 1 in starting of mantissa except 0.


Solution

  • The all 0's pattern is reserved for 0:

                  3  2          1         0
                  1 09876543 21098765432109876543210
                  S ---E8--- ----------F23----------
          Binary: 0 00000000 00000000000000000000000
             Hex: 0000 0000
       Precision: SP
            Sign: Positive
        Exponent: -127 (Stored: 0, Bias: 127)
       Hex-float: 0x0p+0
           Value: +0.0
    

    Note that there are two 0's in the IEEE representation: +0, and -0; which can be distinguished. The pattern 0x80000000 is used for the latter:

                  3  2          1         0
                  1 09876543 21098765432109876543210
                  S ---E8--- ----------F23----------
          Binary: 1 00000000 00000000000000000000000
             Hex: 8000 0000
       Precision: SP
            Sign: Negative
        Exponent: -127 (Stored: 0, Bias: 127)
       Hex-float: -0x0p+0
           Value: -0.0