6667086: Double.doubleToLongBits(final double value) contains inefficient test for NaN
Use isNaN() to test the parameter. Reviewed-by: darcy, psandoz
This commit is contained in:
parent
72803ca57e
commit
bfd742becf
@ -833,14 +833,10 @@ public final class Double extends Number implements Comparable<Double> {
|
|||||||
* @return the bits that represent the floating-point number.
|
* @return the bits that represent the floating-point number.
|
||||||
*/
|
*/
|
||||||
public static long doubleToLongBits(double value) {
|
public static long doubleToLongBits(double value) {
|
||||||
long result = doubleToRawLongBits(value);
|
if (!isNaN(value)) {
|
||||||
// Check for NaN based on values of bit fields, maximum
|
return doubleToRawLongBits(value);
|
||||||
// exponent and nonzero significand.
|
}
|
||||||
if ( ((result & DoubleConsts.EXP_BIT_MASK) ==
|
return 0x7ff8000000000000L;
|
||||||
DoubleConsts.EXP_BIT_MASK) &&
|
|
||||||
(result & DoubleConsts.SIGNIF_BIT_MASK) != 0L)
|
|
||||||
result = 0x7ff8000000000000L;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -741,14 +741,10 @@ public final class Float extends Number implements Comparable<Float> {
|
|||||||
* @return the bits that represent the floating-point number.
|
* @return the bits that represent the floating-point number.
|
||||||
*/
|
*/
|
||||||
public static int floatToIntBits(float value) {
|
public static int floatToIntBits(float value) {
|
||||||
int result = floatToRawIntBits(value);
|
if (!isNaN(value)) {
|
||||||
// Check for NaN based on values of bit fields, maximum
|
return floatToRawIntBits(value);
|
||||||
// exponent and nonzero significand.
|
}
|
||||||
if ( ((result & FloatConsts.EXP_BIT_MASK) ==
|
return 0x7fc00000;
|
||||||
FloatConsts.EXP_BIT_MASK) &&
|
|
||||||
(result & FloatConsts.SIGNIF_BIT_MASK) != 0)
|
|
||||||
result = 0x7fc00000;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user