Java:Math.random()Max Value(double just less than 1) [英] Java: Math.random() Max Value (double just less than 1)
问题描述
Java使用64位 IEEE-754 表示,所以最接近的数字小于1,数字理论上 3FEFFFFFFFFFFFFF
十六进制表示,对于符号为0,对于指数为-1,对于52位有效位为1.99999999999997。这等于大致 0.9999999999999998
。
I've been a little curious about this. Math.random() gives a value in the range [0.0,1.0). So what might the largest value it can give be? In other words, what is the closest double value to 1.0 that is less than 1.0?
Java uses 64-bit IEEE-754 representation, so the closest number smaller than one is theoretically 3FEFFFFFFFFFFFFF
in hexadecimal representation, which is 0 for sign, -1 for the exponent, and 1.9999999999999997 for the 52-bit significand. This equals to roughly 0.9999999999999998
.
References: IEEE-754 Calculator.
这篇关于Java:Math.random()Max Value(double just less than 1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!