Java:Math.random()Max Value(double just less than 1) [英] Java: Math.random() Max Value (double just less than 1)

查看:127
本文介绍了Java:Math.random()Max Value(double just less than 1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此有点好奇。 Math.random()给出范围[0.0,1.0]中的值。那么最大的价值可以是什么呢?换句话说,最接近的double值是1.0,小于1.0?

解决方案

Java使用64位 IEEE-754 表示,所以最接近的数字小于1,数字理论上 3FEFFFFFFFFFFFFF 十六进制表示,对于符号为0,对于指数为-1,对于52位有效位为1.99999999999997。这等于大致 0.9999999999999998



参考文献: IEEE-754计算器


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆