2

Why below program output is 0.0. It is to return the minimum value of Double.

public class Test {
    public static void main(String[] args){
        System.out.println(Math.min(Double.MIN_VALUE, 0.0d)); // 0.0
    }
}

The min value is close to zero but why it is giving 0.0 instead of exact value?

Aajan
  • 927
  • 1
  • 10
  • 23
  • Possible duplicate: http://stackoverflow.com/questions/5709073/is-double-min-value-is-greater-than-zero-in-java – sAm Mar 06 '16 at 09:56
  • Question is why it is printing 0.0 instead of closest value.Didnt getting that from existing question, thats why asked. – Aajan Mar 06 '16 at 10:05

1 Answers1

6

Refer to the JavaDoc for Double.MIN_VALUE

A constant holding the smallest positive nonzero value of type double, 2-1074. It is equal to the hexadecimal floating-point literal 0x0.0000000000001P-1022 and also equal to Double.longBitsToDouble(0x1L).

0.0d is thus smaller than Double.MIN_VALUE

Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89