programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Devaka Cooray
• Ron McLeod
• Jeanne Boyarsky
Sheriffs:
• Liutauras Vilda
• paul wheaton
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Piet Souris
• Carey Brown
• Tim Holloway
Bartenders:
• Martijn Verburg
• Frits Walraven
• Himai Minh

# Wrapper Classes.

Ranch Hand
Posts: 62
• Number of slices to send:
Optional 'thank-you' note:
The following question from dan's single topic exam:
class D {
static boolean m(double v) {
return(v != v == Double.isNaN(v));
}
public static void main (String args[]) {
double d1 = Double.NaN;
double d2 = Double.POSITIVE_INFINITY;
double d3 = Double.MAX_VALUE;
System.out.print(m(d1) + "," + m(d2) + "," + m(d3));
}
}
the ans is true, true true. I expected it to be false , true, true, because, in first case, v==Double.isNaN(v)is true and therefore, v!=v is flase.
Pls clarify

Ranch Hand
Posts: 3271
• Number of slices to send:
Optional 'thank-you' note:
I believe the answer to your question lies in the order in which these operands are evaluated. First, we evaluate v != v, which returns true because Double.NaN is not equal to Double.NaN. Next, we take that result (true) and compare it to the result of Double.isNaN(Double.NaN). That also returns true. Therefore, we finally check to see if true is equivalent to true, which, obviously, it is, and we get a final returned value of true.
I hope that helps,
Corey

Ranch Hand
Posts: 57
• Number of slices to send:
Optional 'thank-you' note:
I think your confusion might simply lie in this fact...at least mine did!!

[ August 18, 2003: Message edited by: Dan Lastoria ]

Jui Mahajan
Ranch Hand
Posts: 62
• Number of slices to send:
Optional 'thank-you' note:
Thank you, I guess that solves the problem.

 Would anybody like some fudge? I made it an hour ago. And it goes well with a tiny ad ... the value of filler advertising in 2021 https://coderanch.com/t/730886/filler-advertising