Note: Similar to Can an integer be NaN in C++?
I understand this has little practical purpose, but can a float
or double
be set to NaN
?
Note: Similar to Can an integer be NaN in C++?
I understand this has little practical purpose, but can a float
or double
be set to NaN
?
The Float object contains a static value, which is a float
type, called NaN
.
So
float myFloat = Float.NaN;
gives you what you are asking.
http://download.oracle.com/javase/6/docs/api/java/lang/Float.html#NaN
float
or double
to NaN, thus making it unusable in any arithmatic. –
Gemmell Sure! NaN is a static constant in the Float and Double classes.
double x = Double.NaN;
jshell> double ddd=Double.NaN; ddd ==> NaN
jshell> ddd!=ddd $5 ==> true
© 2022 - 2024 — McMap. All rights reserved.