I have compiled code that erroneously tries to add a number and Double.NaN. I'm wondering if it's throwing an exception that's not getting caught? Does anyone know how that situation is handled?
Thanks.
我编译了错误地尝试添加数字和Double.NaN的代码。我想知道它是否会抛出一个未被捕获的异常?有谁知道这种情况是如何处理的?谢谢。
3 个解决方案
#1
7
Adding a number to NaN gives NaN. It isn't expected to cause an exception. I understand that this conforms to IEEE 754.
向NaN添加数字会得到NaN。预计不会导致异常。我知道这符合IEEE 754。
#2
1
To answer Steve B's question:
回答Steve B的问题:
POSITIVE_INFINITY is the largest postive number that you can store if you have unlimited storage space. Without this luxury we have to use a construction like 1.0 / 0.0 which does a fine job. Same goes for NEGATIVE_INFINITY but then the largest negative number.
如果您拥有无限的存储空间,POSITIVE_INFINITY是您可以存储的最大正号。如果没有这种奢侈品,我们必须使用像1.0 / 0.0这样的结构。 NEGATIVE_INFINITY也是如此,但是最大的负数。
NaN is normally defined as 0.0 / 0.0 because there is no such number as 0/0 so that perfectly qualifies for a NaN.
NaN通常定义为0.0 / 0.0,因为没有0/0这样的数字,因此完全符合NaN的要求。
#3
0
public static void main(String args[])
{
Double d = Double.NaN + 1.0;
System.out.println(d);
}
prints Double.Nan. Can anyone explain the source implementation?
打印Double.Nan。任何人都可以解释源实现吗?
public static final double POSITIVE_INFINITY = 1.0 / 0.0;
public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
public static final double NaN = 0.0d / 0.0;
#1
7
Adding a number to NaN gives NaN. It isn't expected to cause an exception. I understand that this conforms to IEEE 754.
向NaN添加数字会得到NaN。预计不会导致异常。我知道这符合IEEE 754。
#2
1
To answer Steve B's question:
回答Steve B的问题:
POSITIVE_INFINITY is the largest postive number that you can store if you have unlimited storage space. Without this luxury we have to use a construction like 1.0 / 0.0 which does a fine job. Same goes for NEGATIVE_INFINITY but then the largest negative number.
如果您拥有无限的存储空间,POSITIVE_INFINITY是您可以存储的最大正号。如果没有这种奢侈品,我们必须使用像1.0 / 0.0这样的结构。 NEGATIVE_INFINITY也是如此,但是最大的负数。
NaN is normally defined as 0.0 / 0.0 because there is no such number as 0/0 so that perfectly qualifies for a NaN.
NaN通常定义为0.0 / 0.0,因为没有0/0这样的数字,因此完全符合NaN的要求。
#3
0
public static void main(String args[])
{
Double d = Double.NaN + 1.0;
System.out.println(d);
}
prints Double.Nan. Can anyone explain the source implementation?
打印Double.Nan。任何人都可以解释源实现吗?
public static final double POSITIVE_INFINITY = 1.0 / 0.0;
public static final double NEGATIVE_INFINITY = -1.0 / 0.0;
public static final double NaN = 0.0d / 0.0;