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)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With