wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes pls help on NaN Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "pls help on NaN" Watch "pls help on NaN" New topic
Author

pls help on NaN

teja kumar
Greenhorn

Joined: Jul 24, 2008
Posts: 1
public class MA {
public static void main(String ags[]){
if ((0.0/0.0)==Double.NaN)
System.out.print (0.0/0.0);
System.out.print ("not equal");
}
}
can anyone tell me why output is not equal rather than NaN?
ready
Savithri Devaraj
Ranch Hand

Joined: Jun 26, 2000
Posts: 103
Originally posted by ready:
public class MA {
public static void main(String ags[]){
if ((0.0/0.0)==Double.NaN)
System.out.print (0.0/0.0);
System.out.print ("not equal");
}
}
can anyone tell me why output is not equal rather than NaN?
ready

I remember reading this in RHE. Even (Double.NaN == Double.NaN) returns false. It is just the nature of NaN - it is not a finite quality that can be used for comparison.
Savithri
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
It's discussed fully here http://www.javaranch.com/ubb/Forum24/HTML/002376.html


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

double d1=Double.NaN;
double d2=Double.NaN;
Double D1=new Double(Double.NaN);
Double D2=new Double(Double.NaN);
// always false
if (Double.NaN==Double.NaN) System.out.println("Never Equal");
// true
if (D1.equals(D2)) System.out.println("D1.equals(D2)");
//true
if(D1.isNaN()) System.out.println("D1 is NaN");
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: pls help on NaN
 
Similar Threads
Float Division
why does it say variable not defined
Confusion about Double.NaN
When will we get the value [B]NaN[/B].
About NAN