This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

// Math.sqrt() question

 
Meg Adal
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per API

public static double sqrt(double a)
Returns the square root of a double value.
Parameters:
a - a double value.
Returns:
the square root of a. If the argument is NaN or less than zero, the result is NaN.


So I wrote a code

Why it is not giving me NaN for double
Can anybody explain me or give the link which explains diff. behavior for Double's Min and Max values
Thanks in advance
Megan
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Double.MIN_VALUE is not a negative number. It is the smallest positive number representable as a double.
In my opinion, the designers of Java made a mistake in using the same symbol (MIN_VALUE) to mean two quite different things for Integer vs. Double.
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the definitions for Double.MIN_VALUE and Integer.MIN_VALUE:
static double MIN_VALUE: The smallest positive value of type double.
static int MIN_VALUE: The smallest value of type int.
So, by def'n Double.MIN_VALUE is positive, so you'll get an answer. Integer.MIN_VALUE is negative, so you'll get NaN
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic