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.
-
6See [IEEE floating point](http://en.wikipedia.org/wiki/Ieee_floating_point). – Philip Kendall Dec 17 '13 at 11:43
-
More specifically, http://en.wikipedia.org/wiki/Single_precision_floating-point_format – Jon Dec 17 '13 at 11:44
-
http://en.wikipedia.org/wiki/Floating_point – Thorsten Dittmar Dec 17 '13 at 11:46
-
You were able to represent 3.4e38 using seven characters from the set `0123456789.e\0`; that's less than 26 bits of information. Surely it can be represented in 32 bits! – Stephen Canon Dec 17 '13 at 11:52
1 Answers
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.

- 195,579
- 13
- 168
- 312
-
Note: for fun OP's 3.4e38 --> s = 0, f = 1111_1111_1001_0011_0011_110 and e = 1111_1110. – chux - Reinstate Monica Dec 17 '13 at 18:57