Understanding DBL_MAX

半世苍凉 提交于 2019-12-06 15:30:33

Double are represented as m*2^e where m is the mantissa and e is the exponent. Doubles have 11 bits for the exponent. Since the exponent can be negative there is an offset of 1023. That means that the real calculation is m*2^(e-1023). The largest 11 bit number is 2047. The exponent 2047 is reserved for storing inf and NaN. This means the largest double is m*2^(2046-1023) = m*2^(1023). The mantissa is a number between 1 and 2. This means that the largest double is attained when m is almost 2. So we have:

DBL_MAX = max(m)*2^1023 ~ 2*2^1023 = 2^1024 = 2^(2^10)

As you can see here this is pretty much the standard value of DBL_MAX.

DBL_MAX is the largest value a double can hold. Its value is not related to the number of bits in the mantissa.

The limit is mostly related to the maximum exponent. For IEEE-754, it is about 1.8e+308 or 2^1023.

The definition is usually #define DBL_MAX 1.79769313486231470e+308

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!