Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

max floating point value [duplicate]

I am wondering if the max float represented in IEEE 754 is:

(1.11111111111111111111111)_b*2^[(11111111)_b-127]

Here _b means binary representation. But that value is 3.403201383*10^38, which is different from 3.402823669*10^38, which is (1.0)_b*2^[(11111111)_b-127] and given by for example c++ <limits>. Isn't (1.11111111111111111111111)_b*2^[(11111111)_b-127] representable and larger in the framework?

Does anybody know why?

Thank you.

like image 528
Qiang Li Avatar asked Mar 13 '26 16:03

Qiang Li


2 Answers

The exponent 11111111b is reserved for infinities and NaNs, so your number cannot be represented.

The greatest value that can be represented in single precision, approximately 3.4028235×1038, is actually 1.11111111111111111111111b×211111110b-127.

See also http://en.wikipedia.org/wiki/Single-precision_floating-point_format

like image 54
Joni Avatar answered Mar 16 '26 15:03

Joni


Being the "m" the mantissa and the "e" the exponent, the answer is:

((2 - 2^(-m) * 2^(2^(e-1))))/2

In your case, if the number of bits on IEEE 754 are:

  • 16 Bits you have 1 for the sign, 5 for the exponent and 10 for the mantissa. The largest number represented is 4,293,918,720.
  • 32 Bits you have 1 for the sign, 8 for the exponent and 23 for the mantissa. The largest number represented is 3.402823466E38
  • 64 Bits you have 1 for the sign, 11 for the exponent and 52 for the mantissa. The largest number represented is 21024 - 2971
like image 44
Fernando Pérez Lara Avatar answered Mar 16 '26 16:03

Fernando Pérez Lara



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!