Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is autoboxing/unboxing failing here?

In the program below, the result is that 0.0 is considered less than Double.MIN_VALUE. Why?

We have a solution (work with Doubles only and use compareTo) and I want to understand why unboxing is failing here.

import java.util.Date;
import java.util.Calendar;
import java.math.BigDecimal;

public class Test {

  public static void main(String[] args) {
    double max = 99999.9999;
    double min = Double.MIN_VALUE;
    Double test = 0.0;

    System.out.println(max > test); // expect true; is true
    System.out.println(test > min); // expect true; is false
  }
}
like image 585
Chip McCormick Avatar asked Jul 23 '11 13:07

Chip McCormick


1 Answers

According to the Javadocs :

MIN_VALUE

A constant holding the smallest positive nonzero value of type double, 2-1074.

In other words, it is bigger than 0.

like image 127
Nico Huysamen Avatar answered Oct 17 '22 14:10

Nico Huysamen