File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Math.sqrt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Math.sqrt" Watch "Math.sqrt" New topic
Author

Math.sqrt

kundan varma
Ranch Hand

Joined: Mar 08, 2004
Posts: 322
HI All
can somebody tell me what is the logic behind such output:
System.out.println("Math.sqrt( -9.0 ) \t" + Math.sqrt( -9.0 ) );
System.out.println("Math.sqrt( -0.0 ) \t" + Math.sqrt( -0.0 ) );
System.out.println("Math.sqrt( 0.0 ) \t" + Math.sqrt( 0.0 ) );

OUT PUT IS

Math.sqrt( -9.0 ) NaN
Math.sqrt( -0.0 ) -0.0 //doubt
Math.sqrt( 0.0 ) 0.0

Thanks
kundan


SCJP1.4,SCBCD,SCEA,CNA
Failures are practice shoots for success.
kundan varma
Ranch Hand

Joined: Mar 08, 2004
Posts: 322
Hi All
I got the answer from api which states
"
public static double sqrt(double a)Returns the correctly rounded positive square root of a double value. Special cases:
If the argument is NaN or less than zero, then the result is NaN.
If the argument is positive infinity, then the result is positive infinity.
If the argument is positive zero or negative zero, then the result is the same as the argument.
Otherwise, the result is the double value closest to the true mathetmatical square root of the argument value.
Parameters:
a - a double value.
Returns:
the positive square root of a. If the argument is NaN or less than zero, the result is NaN.
"
THanks
kundan
 
jQuery in Action, 2nd edition
 
subject: Math.sqrt