Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct Way to Obtain The Most Negative Double

Tags:

java

Is this the correct way to obtain the most negative double in Java?

double v = -Double.MAX_VALUE; 
like image 418
Cheok Yan Cheng Avatar asked Mar 05 '10 20:03

Cheok Yan Cheng


People also ask

How do you make the most negative in Python?

If you actually want the most negative value for python, float('-inf') works nicely.

Can a double value be negative?

On all machines, variables of the float, double, and long double data types can store positive or negative numbers.

What is the smallest number a double can hold?

Smallest DOUBLE value: -1.79769E+308. Largest DOUBLE value: 1.79769E+308. Smallest positive DOUBLE value: 2.225E-307. Largest negative DOUBLE value: -2.225E-307.

How small can a double be?

MIN_VALUE is a constant holding the smallest POSITIVE nonzero value of type double, 2^(-1074). The mantissa, always a positive number, holds the significant digits of the floating-point number. The exponent indicates the positive or negative power of the radix that the mantissa and sign should be multiplied by.


2 Answers

Assuming you mean the largest negative, non-infinite number, sounds correct because, for floating point numbers in 64-bit IEEE 754 floating point (which is what Java uses for doubles):

  • The size of the number is stored in one part of the binary rep
  • The sign of the number is stored in a separate part of the binary rep

Therefore: The largest representable negative number would be the same as the largest representable positive number with the sign bit flipped to indicate a negative number.

like image 179
RHSeeger Avatar answered Oct 09 '22 00:10

RHSeeger


Nope, it's Double.NEGATIVE_INFINITY.

like image 25
Sean Owen Avatar answered Oct 09 '22 01:10

Sean Owen