Forums Register Login

Float.NaN question

+Pie Number of slices to send: Send
Hi,

public static void main(String[] args) throws Exception {
if (Float.NaN > Float.POSITIVE_INFINITY) {
System.out.println("Float.NaN is greater");
} else {
System.out.println("Float.POSITIVE_INFINITY is greater");
}
if (Float.POSITIVE_INFINITY > Float.NaN) {
System.out.println("Float.POSITIVE_INFINITY is greater");
} else {
System.out.println("Float.NaN is greater");
}
if(Float.POSITIVE_INFINITY == Float.NaN) {
System.out.println("both are equal");
} else {
System.out.println("both are NOT equal");
}
System.out.println(Float.NaN == Float.NaN);
}


The above code prints,
Float.POSITIVE_INFINITY is greater
Float.NaN is greater
both are NOT equal
false

Can someone pls explain this o/p to me ? Also, Float.NaN is a static field of Float wrapper class, then why is Float.NaN == Float.NaN returning false ?

TIA,
Abhimanyu

[ November 16, 2004: Message edited by: Abhimanyu Kumar ]
[ November 16, 2004: Message edited by: Abhimanyu Kumar ]
+Pie Number of slices to send: Send
Any comparison involving Float.NaN returns false. To check for NaN, use a Float.isNaN() method.
[ November 16, 2004: Message edited by: Mike Gershman ]
In the renaissance, how big were the dinosaurs? Did you have tiny ads?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2553 times.
Similar Threads
Conversion question from Dan's exam
extremes of Math.ceil
Math Class min max ?
Floating-point arithmetic
== operator
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:00:02.