• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

// Math.sqrt() question

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic