mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-01 03:30:34 +00:00
8130234: Get rid of JSType.isNegativeZero
Reviewed-by: hannesw, lagergren
This commit is contained in:
parent
eacc58bf85
commit
2a2f2f3300
@ -353,8 +353,8 @@ final class FoldConstants extends NodeVisitor<LexicalContext> implements Loggabl
|
||||
return null;
|
||||
}
|
||||
|
||||
isInteger &= JSType.isRepresentableAsInt(value) && !JSType.isNegativeZero(value);
|
||||
isLong &= JSType.isRepresentableAsLong(value) && !JSType.isNegativeZero(value);
|
||||
isInteger &= JSType.isStrictlyRepresentableAsInt(value);
|
||||
isLong &= JSType.isStrictlyRepresentableAsLong(value);
|
||||
|
||||
if (isInteger) {
|
||||
return LiteralNode.newInstance(token, finish, (int)value);
|
||||
|
||||
@ -1640,9 +1640,9 @@ public class Lexer extends Scanner {
|
||||
//and new Color(float, float, float) will get ambiguous for cases like
|
||||
//new Color(1.0, 1.5, 1.5) if we don't respect the decimal point.
|
||||
//yet we don't want e.g. 1e6 to be a double unnecessarily
|
||||
if (JSType.isRepresentableAsInt(value) && !JSType.isNegativeZero(value)) {
|
||||
if (JSType.isStrictlyRepresentableAsInt(value)) {
|
||||
return (int)value;
|
||||
} else if (JSType.isRepresentableAsLong(value) && !JSType.isNegativeZero(value)) {
|
||||
} else if (JSType.isStrictlyRepresentableAsLong(value)) {
|
||||
return (long)value;
|
||||
}
|
||||
return value;
|
||||
|
||||
@ -376,8 +376,8 @@ public enum JSType {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if double number can be represented as an int. Note that it returns true for negative zero. If you
|
||||
* need to exclude negative zero, combine this check with {@link #isNegativeZero(double)}.
|
||||
* Returns true if double number can be represented as an int. Note that it returns true for negative
|
||||
* zero. If you need to exclude negative zero, use {@link #isStrictlyRepresentableAsInt(double)}.
|
||||
*
|
||||
* @param number a double to inspect
|
||||
*
|
||||
@ -387,6 +387,18 @@ public enum JSType {
|
||||
return (int)number == number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if double number can be represented as an int. Note that it returns false for negative
|
||||
* zero. If you don't need to distinguish negative zero, use {@link #isRepresentableAsInt(double)}.
|
||||
*
|
||||
* @param number a double to inspect
|
||||
*
|
||||
* @return true for int representable doubles
|
||||
*/
|
||||
public static boolean isStrictlyRepresentableAsInt(final double number) {
|
||||
return isRepresentableAsInt(number) && isNotNegativeZero(number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Object can be represented as an int
|
||||
*
|
||||
@ -402,8 +414,8 @@ public enum JSType {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if double number can be represented as a long. Note that it returns true for negative zero. If you
|
||||
* need to exclude negative zero, combine this check with {@link #isNegativeZero(double)}.
|
||||
* Returns true if double number can be represented as a long. Note that it returns true for negative
|
||||
* zero. If you need to exclude negative zero, use {@link #isStrictlyRepresentableAsLong(double)}.
|
||||
*
|
||||
* @param number a double to inspect
|
||||
* @return true for long representable doubles
|
||||
@ -412,6 +424,18 @@ public enum JSType {
|
||||
return (long)number == number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if double number can be represented as a long. Note that it returns false for negative
|
||||
* zero. If you don't need to distinguish negative zero, use {@link #isRepresentableAsLong(double)}.
|
||||
*
|
||||
* @param number a double to inspect
|
||||
*
|
||||
* @return true for long representable doubles
|
||||
*/
|
||||
public static boolean isStrictlyRepresentableAsLong(final double number) {
|
||||
return isRepresentableAsLong(number) && isNotNegativeZero(number);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Object can be represented as a long
|
||||
*
|
||||
@ -427,12 +451,12 @@ public enum JSType {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the number is the negative zero ({@code -0.0d}).
|
||||
* Returns true if the number is not the negative zero ({@code -0.0d}).
|
||||
* @param number the number to test
|
||||
* @return true if it is the negative zero, false otherwise.
|
||||
* @return true if it is not the negative zero, false otherwise.
|
||||
*/
|
||||
public static boolean isNegativeZero(final double number) {
|
||||
return number == 0.0d && Double.doubleToRawLongBits(number) == 0x8000000000000000L;
|
||||
private static boolean isNotNegativeZero(final double number) {
|
||||
return Double.doubleToRawLongBits(number) != 0x8000000000000000L;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -184,7 +184,7 @@ public final class OptimisticReturnFilters {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static int ensureInt(final double arg, final int programPoint) {
|
||||
if (JSType.isRepresentableAsInt(arg) && !JSType.isNegativeZero(arg)) {
|
||||
if (JSType.isStrictlyRepresentableAsInt(arg)) {
|
||||
return (int)arg;
|
||||
}
|
||||
throw new UnwarrantedOptimismException(arg, programPoint);
|
||||
@ -206,7 +206,7 @@ public final class OptimisticReturnFilters {
|
||||
// Long into the exception.
|
||||
if (isPrimitiveNumberWrapper(arg)) {
|
||||
final double d = ((Number)arg).doubleValue();
|
||||
if (JSType.isRepresentableAsInt(d) && !JSType.isNegativeZero(d)) {
|
||||
if (JSType.isStrictlyRepresentableAsInt(d)) {
|
||||
return (int)d;
|
||||
}
|
||||
}
|
||||
@ -239,7 +239,7 @@ public final class OptimisticReturnFilters {
|
||||
}
|
||||
|
||||
private static long ensureLong(final double arg, final int programPoint) {
|
||||
if (JSType.isRepresentableAsLong(arg) && !JSType.isNegativeZero(arg)) {
|
||||
if (JSType.isStrictlyRepresentableAsLong(arg)) {
|
||||
return (long)arg;
|
||||
}
|
||||
throw new UnwarrantedOptimismException(arg, programPoint);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user