Use floating point comparison for all non-integral Number types (such as LazilyParsedNumber)
This commit is contained in:
parent
2ee89879e1
commit
2f0c617d8d
@ -318,7 +318,7 @@ public final class JsonPrimitive extends JsonElement {
|
|||||||
long value = getAsNumber().longValue();
|
long value = getAsNumber().longValue();
|
||||||
return (int) (value ^ (value >>> 32));
|
return (int) (value ^ (value >>> 32));
|
||||||
}
|
}
|
||||||
if (isFloatingPoint(this)) {
|
if (value instanceof Number) {
|
||||||
long value = Double.doubleToLongBits(getAsNumber().doubleValue());
|
long value = Double.doubleToLongBits(getAsNumber().doubleValue());
|
||||||
return (int) (value ^ (value >>> 32));
|
return (int) (value ^ (value >>> 32));
|
||||||
}
|
}
|
||||||
@ -340,7 +340,7 @@ public final class JsonPrimitive extends JsonElement {
|
|||||||
if (isIntegral(this) && isIntegral(other)) {
|
if (isIntegral(this) && isIntegral(other)) {
|
||||||
return getAsNumber().longValue() == other.getAsNumber().longValue();
|
return getAsNumber().longValue() == other.getAsNumber().longValue();
|
||||||
}
|
}
|
||||||
if (isFloatingPoint(this) && isFloatingPoint(other)) {
|
if (value instanceof Number && other.value instanceof Number) {
|
||||||
double a = getAsNumber().doubleValue();
|
double a = getAsNumber().doubleValue();
|
||||||
// Java standard types other than double return true for two NaN. So, need
|
// Java standard types other than double return true for two NaN. So, need
|
||||||
// special handling for double.
|
// special handling for double.
|
||||||
@ -362,15 +362,4 @@ public final class JsonPrimitive extends JsonElement {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if the specified number is a floating point type (BigDecimal, double, float)
|
|
||||||
*/
|
|
||||||
private static boolean isFloatingPoint(JsonPrimitive primitive) {
|
|
||||||
if (primitive.value instanceof Number) {
|
|
||||||
Number number = (Number) primitive.value;
|
|
||||||
return number instanceof BigDecimal || number instanceof Double || number instanceof Float;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user