The IEEE 754 format has one bit reserved for the sign and the remaining bits representing the magnitude. This means that it is "symmetrical" around origo (as opposed to the Integer values, which have one more negative value). Thus the minimum value is simply the same as the maximum value, with the sign-bit flipped, so yes, -Double.MAX_VALUE is the lowest actual number you can represent with a double.

I suppose the Double.MAX_VALUE should be seen as maximum magnitude, in which case it actually makes sense to simply write -Double.MAX_VALUE. It also explains why Double.MIN_VALUE is the least positive value (since that represents the least possible magnitude).

But sure, I agree that the naming is a bit misleading. Being used to the meaning Integer.MIN_VALUE, I too was a bit surprised when I read that Double.MIN_VALUE was the smallest absolute value that could be represented. Perhaps they thought it was superfluous to have a constant representing the least possible value as it is simply a - away from MAX_VALUE :-)

(Note, there is also Double.NEGATIVE_INFINITY but I'm disregarding from this, as it is to be seen as a "special case" and does not in fact represent any actual number.)

Here is a good text on the subject.

Answer from aioobe on Stack Overflow
Top answer
1 of 6
225

The IEEE 754 format has one bit reserved for the sign and the remaining bits representing the magnitude. This means that it is "symmetrical" around origo (as opposed to the Integer values, which have one more negative value). Thus the minimum value is simply the same as the maximum value, with the sign-bit flipped, so yes, -Double.MAX_VALUE is the lowest actual number you can represent with a double.

I suppose the Double.MAX_VALUE should be seen as maximum magnitude, in which case it actually makes sense to simply write -Double.MAX_VALUE. It also explains why Double.MIN_VALUE is the least positive value (since that represents the least possible magnitude).

But sure, I agree that the naming is a bit misleading. Being used to the meaning Integer.MIN_VALUE, I too was a bit surprised when I read that Double.MIN_VALUE was the smallest absolute value that could be represented. Perhaps they thought it was superfluous to have a constant representing the least possible value as it is simply a - away from MAX_VALUE :-)

(Note, there is also Double.NEGATIVE_INFINITY but I'm disregarding from this, as it is to be seen as a "special case" and does not in fact represent any actual number.)

Here is a good text on the subject.

2 of 6
14

These constants have nothing to do with sign. This makes more sense if you consider a double as a composite of three parts: Sign, Exponent and Mantissa. Double.MIN_VALUE is actually the smallest value Mantissa can assume when the Exponent is at minimun value before a flush to zero occurs. Likewise MAX_VALUE can be understood as the largest value Mantissa can assume when the Exponent is at maximum value before a flush to infinity occurs.

A more descriptive name for these two could be Largest Absolute (add non-zero for verbositiy) and Smallest Absolute value (add non-infinity for verbositiy).

Check out the IEEE 754 (1985) standard for details. There is a revised (2008) version, but that only introduces more formats which aren't even supported by java (strictly speaking java even lacks support for some mandatory features of IEEE 754 1985, like many other high level languages).

🌐
Programming.Guide
programming.guide › java › double-min-value-vs-double-min-normal.html
Java: Double.MIN_VALUE vs Double.MIN_NORMAL | Programming.Guide
Double.MIN_VALUE is the overall smallest possible value a double can represent. Double.MIN_NORMAL is the smallest possible value which is still a normal value (i.e. not subnormal).
🌐
LabEx
labex.io › tutorials › java-java-double-min-method-117625
Mastering the Java Double Min Method | LabEx
In Java, the Double.min() method is used to find the smallest of two double values passed as arguments. It returns the numerically lower value of the two values passed.
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java math min() method
Java - Math min(double x, double y) Method
September 1, 2008 - The Java Math min(double a, double b) returns the smaller of two double values. That is, the result is the value closer to negative infinity. If the arguments have the same value, the result is that same value.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.double.minvalue
Double.MinValue Field (Java.Lang) | Microsoft Learn
A constant holding the smallest positive nonzero value of type double, 2<sup>-1074</sup>. It is equal to the hexadecimal floating-point literal 0x0.0000000000001P-1022 and also equal to Double.longBitsToDouble(0x1L).
🌐
Programming.Guide
programming.guide › java › integer-minvalue-negative-double-minvalue-positive.html
Java: Why's Double.MIN_VALUE is positive? Integer.MIN_VALUE is negative! | Programming.Guide
This is a positive value, as opposed to Integer.MIN_VALUE which holds the negative value -2147483648. The reason is most likely that the smallest double value is easily expressed as -Double.MAX_VALUE. The IEEE 754 format has one bit reserved for the sign and the remaining bits representing ...
🌐
MIT
web.mit.edu › java_v1.0.2 › www › javadoc › java.lang.Double.html
Class java.lang.Double
The lowest minimum value that a double can have is 2.2250738585072014E-308.
🌐
Javatpoint
javatpoint.com › java-double-min-method
Java Double min() Method - Javatpoint
The min() method of Java Double class returns the double having minor value amongst two double values. The result returned is same as by invoking Math.min () method.
Find elsewhere
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Double.html
Double (Java Platform SE 8 )
October 20, 2025 - Returns the smaller of two double values as if by calling Math.min. ... Java™ Platform Standard Ed.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › Double.html
Double (Java Platform SE 7 )
Note that the round-to-nearest ... or equal to (MAX_VALUE + ulp(MAX_VALUE)/2), rounding to double will result in an infinity and if the exact value of s is small enough in magnitude (less than or equal to MIN_VALUE/2), rounding to float will result in a zero....
🌐
Java Tutorial HQ
javatutorialhq.com › java tutorial › java.lang › double › min(double a,double b) method example
Java Double min(double a,double b) method example
September 30, 2019 - package com.javatutorialhq.java.examples; import static java.lang.System.out; /* * This example source code demonstrates the use of * min(double a,double b) method of Double class */ public class DoubleMin { public static void main(String[] args) { Double val1 = 4.99; Double val2 = 0.0 / 0.0; Double val3 = 1033.0 / 0; Double val4 = -val1 / 0.0; Double val5 = -916445.92; Double val6 = 0.0; /* * test all the possible scenario on using the * min(double a,double b) method * Note, this only works using java 8 */ out.println("Smallest Between "+val1+" and "+val2+ " = " + Double.max(val1, val2)); out
🌐
Coderanch
coderanch.com › t › 388349 › java › minimum-float-double
minimum float/double (Beginning Java forum at Coderanch)
Any advice is much appreciated. Thanks. Stephaie ... Hi, Stephanie. Can't you just refer to -Float.MAX_VALUE and -Double.MAX_VALUE? According to Java in a Nutshell, the range for floats is +/-1.4E-45 to +/-3.4028235E+38 and for doubles is +/-4.9E-324 to +/-1.7976931348623157E+308.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-guava-doubles-min-method-with-examples
Java Guava | Doubles.min() method with Examples - GeeksforGeeks
July 11, 2025 - Return Value: This method returns a double value that is the minimum value in the specified array. Exceptions: The method throws IllegalArgumentException if the array is empty. Below programs illustrate the use of the above method: Example 1 ...
🌐
Tpoint Tech
tpointtech.com › java-double-min-method
Java Double min() Method - Tpoint Tech
March 17, 2025 - The min() method of Java Double class returns the double having minor value amongst two double values. The result returned is same as by invoking Math.
🌐
OpenJDK
bugs.openjdk.org › browse › JDK-4218647
"Math.min(0d, Double.MIN_VALUE)" equals "0"
Name: dbT83986 Date: 03/09/99 Maybe I'm missing something, but I seem to be getting weird results with Math.max() and Math.min() when comparing zero with MIN_VALUE MAX_VALUE. Below is the code, and then the results: System.out.println(Math.min(0d, Double.MIN_VALUE)); // Wrong 0.0 System.out.println(Math.min(0d, Double.MAX_VALUE)); // 0.0 System.out.println(Math.max(0d, Double.MIN_VALUE)); // Wrong 4.9E-324 System.out.println(Math.max(0d, Double.MAX_VALUE)); // 1.7976931348623157E308 System.out.println(0d > Double.MIN_VALUE)); // Wrong false System.out.println(0d > Double.MAX_VALUE); // false System.out.println(0d < Double.MIN_VALUE); // Wrong true System.out.println(0d < Double.MAX_VALUE); // true Results: 0.0 0.0 4.9E-324 1.7976931348623157E308 false false true true (Review ID: 54459) ======================================================================
Top answer
1 of 3
5

Try changing this:

double max = Double.MAX_VALUE;
double min = Double.MIN_VALUE;

to this:

double max = -Double.MAX_VALUE;
double min = Double.MAX_VALUE;

After all, if you start off thinking you've already seen MAX_VALUE as the highest, you're never going to see anything greater than that, are you?

EDIT: Note the use of -Double.MAX_VALUE here, instead of Double.MIN_VALUE. MIN_VALUE is the smallest positive number, whereas I assume you really want "the most strongly negative finite value".

You want the first value you read to replace both max and min. An alternative would be to use Double instead, to represent the "missing" value with null to start with:

Double max = null;
Double min = null;

if (max == null || mag > max)
{
    max = mag;
}
// Ditto for min

As a style issue, I'd also only compute the average after you've read the whole of the input - you're repeatedly overwriting the value for no reason. The only reason not to do this is to avoid having to think about the case where count is 0 (i.e. an empty file) but I'd personally handle that separately anyway - when you have no values, there simply isn't an average.

2 of 3
3

dont use Double.MIN_VALUE its not what you expect it to be

Double.MIN_VALUE its not a negative number Double.MIN_VALUE is a very small nummber its 4.9e-324; // 0x0.0000000000001P-1022

Comparing with it will break as soon as you use negative numbers

A small utility class i wrote to help with it:

public class MinMaxUtil<T extends Comparable<T>>
{
  private T minimum;
  private T maximum;

  public MinMaxUtil()
  {
    reset();
  }

  public void check( T value)
  {
    if ( minimum == null || value.compareTo(minimum) < 0  )
      minimum = value;
    if ( maximum == null || value.compareTo(maximum) > 0 )
      maximum = value;
  }

  public void check( T [] values )
  {
    for (T value : values)
      {
      check(value);
      }
  }

  public void check( Collection<T> values )
  {
    for (T value : values)
      {
      check(value);
      }
  }

  public T getMinimum()
  {
    return minimum;
  }

  public T getMaximum()
  {
    return maximum;
  }

  public void reset()
  {
    minimum = null;
    maximum = null;
  }

  @Override
  public String toString()
  {
    return "MinMaxUtil{"+
        "minimum="+minimum+
        ", maximum="+maximum+
        '}';
  }
}
🌐
Programming.Guide
programming.guide › java › double-range.html
Java: Range of a double | Programming.Guide
Integer.MIN_VALUE is negative! The constant Double.MIN_VALUE is the smallest value greater than 0, i.e. not the smallest possible value.