Double.isFinite implementation detail - why DoubleConsts.MAX_VALUE rather than Double.MAX_VALUE?

Hulk :

I looked up the implementation of Double.isFinite() which exists since java 8 (because I needed the functionality in java 7):

public static boolean isFinite(double d) {
    return Math.abs(d) <= DoubleConsts.MAX_VALUE;
}

where DoubleConsts.MAX_VALUE is double sun.misc.DoubleConsts.MAX_VALUE with the value 1.7976931348623157E308. This seems to be equivalent to Double.MAX_VALUE, which is defined as:

public static final double MAX_VALUE = 0x1.fffffffffffffP+1023; // 1.7976931348623157e+308

Why does this implementation use the constant from the sun.misc-package instead of Double.MAX_VALUE?

(Float.isFinite uses the same pattern)

Hulk :

The reason seems to be mostly a historic one:

The funtionality provided by these methods was previously located in sun.misc.FpUtils. This class does not directly depend on Double, it only imports

import sun.misc.FloatConsts;
import sun.misc.DoubleConsts;

so the implementation made more sense there - it seems that it was exactly the same:

public static boolean isFinite(double d) {
    return Math.abs(d) <= DoubleConsts.MAX_VALUE;
}

See also The ticket that led to moving this to Double

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=436204&siteId=1