sách gpt4 ăn đã đi

Java isNan 是如何工作的?

In lại 作者:太空狗 更新时间:2023-10-29 22:39:21 25 4
mua khóa gpt4 giày nike

我在看openjdk-1.7.0_25源码,看到了这个方法:

/**
* Returns {@code true} if the specified number is a
* Not-a-Number (NaN) value, {@code false} otherwise.
*
* @param v the value to be tested.
* @return {@code true} if the argument is NaN;
* {@code false} otherwise.
*/
static public boolean isNaN(float v) {
return (v != v);
}

我不明白它是如何工作的,这个方法什么时候可以返回ĐÚNG VẬY?

câu trả lời hay nhất

该方法可以为某些操作返回ĐÚNG VẬY,例如:

System.out.println(Float.isNaN(0.0f / 0.0f));
System.out.println(Double.isNaN(Math.sqrt(-1)));

基本上,NaN 表示一个未定义的值。 0.0/0.0 的值为NaN,并且Nan != NaN。这看起来合乎逻辑,因为 Math.sqrt(-1) 也给你 NaN

参见 Double.NaN 的 javadoc :

It is equivalent to the value returned by Double.longBitsToDouble(0x7ff8000000000000L)

Sau đó Double.longBitsToDouble() :

If the argument is any value in the range 0x7ff0000000000001L through 0x7fffffffffffffffL or in the range 0xfff0000000000001L through 0xffffffffffffffffL, the result is a NaN. No IEEE 754 floating-point operation provided by Java can distinguish between two NaN values of the same type with different bit patterns.

关于Java isNan 是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18442503/

25 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress