0

What NaN in java

When we divide float 0.0f with same 0.0f then the output is NaN. Why this NaN & what is the meaning of it? For example:- The output of below code is "Nan". Why this and so what is the meaning of NaN? float a=0.0f; float b=a; System.out.println(a/b); O/p: NaN

29th Jul 2017, 4:04 PM
Junaid Khan
Junaid Khan - avatar
4 Respostas
+ 2
Not a Number, you try to divide 0/0 it is an "anomaly" in maths and leads to undefined behaviour. Computer cannot calculate this, so it outputs NaN
29th Jul 2017, 4:10 PM
Jakub Stasiak
Jakub Stasiak - avatar
+ 1
But if both variables are int then it will throw an ArithmeticException but if anyone of both variables is float then it will print NaN. Is there any reason, means anyone know it?
29th Jul 2017, 4:28 PM
Junaid Khan
Junaid Khan - avatar
0
Thanks Jakub Stasiak...
29th Jul 2017, 4:13 PM
Junaid Khan
Junaid Khan - avatar