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
226

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).
🌐
Tutorialspoint
tutorialspoint.com › java › lang › math_min_double.htm
Java - Math min(double x, double y) Method
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.
🌐
Javatpoint
javatpoint.com › java-double-min-method
Java Double min() Method with Examples
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.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-guava-doubles-min-method-with-examples
Java Guava | Doubles.min() method with Examples - GeeksforGeeks
July 11, 2025 - Doubles.min() is a method of Doubles Class in Guava library which is used to find the least value present in an array. The value returned by this method is the smallest double value in the specified array.
🌐
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.
🌐
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.
Find elsewhere
🌐
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 - Returns the smaller of two double values as if by calling Math.min. ... 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 ...
🌐
Java2s
java2s.com › example › java-api › java › lang › double › min_value-0.html
Example usage for java.lang Double MIN_VALUE
public static void main(String args[]) { // integers//w w w . j a va2s.c o m byte smallestByte = Byte.MIN_VALUE; short smallestShort = Short.MIN_VALUE; int smallestInteger = Integer.MIN_VALUE; long smallestLong = Long.MIN_VALUE; // real numbers float smallestFloat = Float.MIN_VALUE; double smallestDouble = Double.MIN_VALUE; // display them all System.out.println("The smallest byte value is " + smallestByte); System.out.println("The smallest short value is " + smallestShort); System.out.println("The smallest integer value is " + smallestInteger); System.out.println("The smallest long value is "
🌐
Java Guides
javaguides.net › 2024 › 06 › java-double-max-and-min-methods.html
Java Double max() and min() Methods
June 17, 2024 - The syntax for the Double.min() method is as follows: ... The smaller of the two double values.
🌐
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.
🌐
LabEx
labex.io › labs › java-java-double-min-method-117625
Mastering the Java Double Min Method
Discover the power of the Java Double.min() method and learn how to use it effectively in your programming projects.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Double.html
Double (Java Platform SE 8 )
July 21, 2026 - Returns the smaller of two double values as if by calling Math.min. ... Java™ Platform Standard Ed.
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+
        '}';
  }
}
🌐
Tutorial Gateway
tutorialgateway.org › java-min-function
Java min Function
April 2, 2016 - Next, we used the Java Math.min Function on variables b, c, d, and e (they belong to the double type). The following three statements will call the double type ( static double min(double a, double b) ) method and find the smallest among the values.
🌐
GeeksforGeeks
geeksforgeeks.org › java › doublestream-min-java-examples
DoubleStream min() in Java with examples - GeeksforGeeks
December 6, 2018 - It helps to solve the problems ... in a new way. DoubleStream min() returns an OptionalDouble describing the minimum element of this stream, or an empty optional if this stream is empty....