• Post Reply Bookmark Topic Watch Topic
  • New Topic
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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Math.sqrt

 
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
kundan varma
Ranch Hand
Posts: 323
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic