In Java, what does NaN mean?

2019-01-01 06:50发布

I have a program that tries to shrink a double down to a desired number. The output I get is NaN.

What does NaN mean in Java?

标签: java nan
10条回答
梦该遗忘
2楼-- · 2019-01-01 07:27

Taken from this page:

"NaN" stands for "not a number". "Nan" is produced if a floating point operation has some input parameters that cause the operation to produce some undefined result. For example, 0.0 divided by 0.0 is arithmetically undefined. Taking the square root of a negative number is also undefined.

查看更多
永恒的永恒
3楼-- · 2019-01-01 07:28

NaN = Not a Number.

查看更多
余欢
4楼-- · 2019-01-01 07:30

NaN means "Not a Number" and is the result of undefined operations on floating point numbers like for example dividing zero by zero. (Note that while dividing a non-zero number by zero is also usually undefined in mathematics, it does not result in NaN but in positive or negative infinity).

查看更多
零度萤火
5楼-- · 2019-01-01 07:30

NaN means "Not a number." It's a special floating point value that means that the result of an operation was not defined or not representable as a real number.

See here for more explanation of this value.

查看更多
何处买醉
6楼-- · 2019-01-01 07:35

Not a Java guy, but in JS and other languages I use it's "Not a Number", meaning some operation caused it to become not a valid number.

查看更多
旧人旧事旧时光
7楼-- · 2019-01-01 07:36

Means Not a Number. It is a common representation for an impossible numeric value in many programming languages.

查看更多
登录 后发表回答