Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Infinity and NaN (Not a number)

Tags:

java

When does java print Infinity and when does it print NaN?

Why is 1.0/0.0 infinity but ((1.0/0.0) - (1.0/0.0)) NaN and 0.0f/0.0f an NaN?

What is the difference between these two?

like image 291
Tarun Mohandas Avatar asked Mar 05 '13 00:03

Tarun Mohandas


People also ask

What does NaN mean in numbers?

NaN (Not a Number) is a numeric data type that means an undefined value or value that cannot be represented, especially results of floating-point calculations.

What category do NaN and infinity come under?

Contents. INF ("infinity"), NAN ("not a number"), and Null are special-valued system constants that Analytica returns in particular conditions, such as exceptions. These constants can also be used as values in expressions. An indeterminant number, which is a numeric value that is not well-defined, such as 0/0 .

What is INF NaN?

Inf and -Inf are positive and negative infinity whereas NaN means 'Not a Number'. (These apply to numeric values and real and imaginary parts of complex values but not to values of integer vectors.) Inf and NaN are reserved words in the R language.

What is NaN and INF in Python?

For those who are unfamiliar with the notation of inf and NaN , they stand for infinity and Not-a-Number , respectively. Even though infinity can be thought of as an extremely very large number, it has no end. We can define the negative infinity as -inf and the positive infinity as inf in Python.


1 Answers

Because Java is following known math facts. 1.0 / 0.0 is infinity, but the others are indeterminate forms, which Java represents as NaN (not a number).

like image 191
rgettman Avatar answered Oct 15 '22 15:10

rgettman