3

As with 32 bit we can only store 2^32 bit data. In C language, How can we store such large value 3.4e38. I am unable to understand the mechanism behind it.

Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281

1 Answers1

3

In the IEEE-754 32-bit binary floating-point format, the 32 bits are used as:

  • A one-bit sign field, s.
  • An eight-bit exponent field, e.
  • A 23-bit significand (fraction) field, f.

These fields encode values:

  • If all bits are on in e and f is non-zero, the value is a NaN (Not a Number).

  • If all bits are on in e and f is zero, the value is +∞ (infinity) if s is 0 and -∞ if s is 1.

  • If e is zero, the value is (-1)s(0+f•2-23)•2-126.

  • Otherwise, the value is (-1)s(1+f•2-23)•2e-127.

Some notes about this:

  • (-1)s sets the sign. This expression is +1 if s is zero and -1 if s is one.
  • The third case includes zeros and what are called subnormal numbers. In this case, an extra zero bit is prefixed to the fraction field.
  • The fourth case is the normal case. It includes most of the floating-point values. In this case, an extra one bit is prefixed to the fraction field.

Computer hardware (or software) manipulates these bits in such a way as to make arithmetic work. For example, when perform addition, the hardware (in effect) shifts bits of the significands to adjust for the difference in exponents, then adds the significands, then rounds to fit into the bits available for it. Additionally, if the addition made the significand larger than the bits available for it, it is shifted right (to make it fit), and the exponent is increased by one.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312