- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
为什么结果是:
double a = 0.0/0.0;
double b = 0/0.0;
= NaN
但是结果例如:
double e = 0.1/0.0;
double e = 12.0/0.0;
double f = 1.0/0.0;
= 无限
我知道 double
或 float
划分在某种程度上有点不同。我对生成的 NaN 非常满意,因为当某个值除以零时,结果未定义。但为什么他们定义大于零除以零的结果是 Infitity?这与他们用来执行浮点除法的方法有关吗?
最佳答案
JLS 15.17.2明确指出
Division of a zero by a zero results in NaN; division of zero by any other finite value results in a signed zero. The sign is determined by the rule stated above.
Division of a nonzero finite value by a zero results in a signed infinity. The sign is determined by the rule stated above.
JLS 也说了这些常量在操作上的区别。
If either operand is NaN, the result is NaN.
Division of an infinity by an infinity results in NaN.
Division of an infinity by a finite value results in a signed infinity. The sign is determined by the rule stated above.
一点也不矛盾。
关于java - 双除以零 : Why is the result inconsistent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43983692/
我是一名优秀的程序员,十分优秀!