Java Float.isNaN Double.isNaN方法工作原理
来源:互联网 发布:数据库完整性约束条件 编辑:程序博客网 时间:2024/06/06 04:50
Floating-point equality testing is performed in accordance with the rules of the IEEE 754 standard:
If either operand is NaN, then the result of == is false but the result of != is true. Indeed, the test x!=x is true if and only if the value of x is NaN. (The methods Float.isNaN and Double.isNaN may also be used to test whether a value is NaN.)
Positive zero and negative zero are considered equal. Therefore, -0.0==0.0 is true, for example.
Otherwise, two distinct floating-point values are considered unequal by the equality operators. In particular, there is one value representing positive infinity and one value representing negative infinity; each compares equal only to itself, and each compares unequal to all other values.
Floating-point equality testing is performed in accordance with the rules of the IEEE 754 standard:
If either operand is NaN, then the result of == is false but the result of != is true. Indeed, the test x!=x is true if and only if the value of x is NaN. (The methods Float.isNaN and Double.isNaN may also be used to test whether a value is NaN.)
Positive zero and negative zero are considered equal. Therefore, -0.0==0.0 is true, for example.
Otherwise, two distinct floating-point values are considered unequal by the equality operators. In particular, there is one value representing positive infinity and one value representing negative infinity; each compares equal only to itself, and each compares unequal to all other values.
That method can return true for certain operations, for example:
System.out.println(Float.isNaN(0.0f / 0.0f));System.out.println(Double.isNaN(Math.sqrt(-1)));
Basically, NaN
represents an undefined value. The value of 0.0 / 0.0
is NaN
, and Nan != NaN
. It may seem logical because Math.sqrt(-1)
also gives you NaN
.
See the javadoc of Double.NaN
:
It is equivalent to the value returned by
Double.longBitsToDouble(0x7ff8000000000000L)
And then Double.longBitsToDouble()
:
If the argument is any value in the range
0x7ff0000000000001L
through0x7fffffffffffffffL
or in the range0xfff0000000000001L
through0xffffffffffffffffL
, the result is aNaN
. No IEEE 754 floating-point operation provided by Java can distinguish between two NaN values of the same type with different bit patterns.
Floating-point equality testing is performed in accordance with the rules of the IEEE 754 standard:
If either operand is NaN, then the result of == is false but the result of != is true. Indeed, the test x!=x is true if and only if the value of x is NaN. (The methods Float.isNaN and Double.isNaN may also be used to test whether a value is NaN.)
Positive zero and negative zero are considered equal. Therefore, -0.0==0.0 is true, for example.
Otherwise, two distinct floating-point values are considered unequal by the equality operators. In particular, there is one value representing positive infinity and one value representing negative infinity; each compares equal only to itself, and each compares unequal to all other values.
- Java Float.isNaN Double.isNaN方法工作原理
- Float 的isNan 方法
- Float.isNaN() 方法
- Float与Double的isNaN()
- Float与Double的isNaN()
- float.isNaN()
- isNaN()
- isNaN
- isNaN
- Float isNaN() 样例
- JavaScript isNaN() 方法 用法
- JavaScript中的isNaN()方法
- 自己总结:java split 方法,js isNaN方法
- isNaN解盲
- isnan isinf
- matlab isnan
- isNaN()函数
- JavaScript : isNaN()和Number.isNan()
- 【剑指offer】树的子结构
- how to build a git server
- 同一页面弹框打开框 打开对应id对话框
- 学习笔记--Android Studio运行java程序
- 【转】Oracle REGEXP_LIKE介绍和例子
- Java Float.isNaN Double.isNaN方法工作原理
- 快速排序 c#实现
- shiro之自动过虑URL,无需配置。
- CTP源码分析5 CTP链路质量估计层结构及源码分析(四)----源码实现解读(一)
- Java网络编程Demo(一)多线程的TCP网络程序
- docker环境搭建
- caffe源码中的common_layers
- Android 自定义View——BarrageView实现弹幕功能
- SpringMVC与Mybatis集合实现调用存储过程、事务控制