# HG changeset patch # User attila # Date 1435827335 -7200 # Node ID 77f783445d409eebfc023c93aaf2ca74b584cefe # Parent fcccd041e11b931355207e4c1768e6a40f675195 8130234: Get rid of JSType.isNegativeZero Reviewed-by: hannesw, lagergren diff -r fcccd041e11b -r 77f783445d40 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FoldConstants.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FoldConstants.java Wed Jul 01 16:26:25 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/FoldConstants.java Thu Jul 02 10:55:35 2015 +0200 @@ -353,8 +353,8 @@ 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); diff -r fcccd041e11b -r 77f783445d40 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Lexer.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Lexer.java Wed Jul 01 16:26:25 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Lexer.java Thu Jul 02 10:55:35 2015 +0200 @@ -1640,9 +1640,9 @@ //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; diff -r fcccd041e11b -r 77f783445d40 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java Wed Jul 01 16:26:25 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/JSType.java Thu Jul 02 10:55:35 2015 +0200 @@ -376,8 +376,8 @@ } /** - * 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 * @@ -388,6 +388,18 @@ } /** + * 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 * * @param obj an object to inspect @@ -402,8 +414,8 @@ } /** - * 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 @@ -413,6 +425,18 @@ } /** + * 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 * * @param obj an object to inspect @@ -427,12 +451,12 @@ } /** - * 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; } /** diff -r fcccd041e11b -r 77f783445d40 nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/OptimisticReturnFilters.java --- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/OptimisticReturnFilters.java Wed Jul 01 16:26:25 2015 +0200 +++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/OptimisticReturnFilters.java Thu Jul 02 10:55:35 2015 +0200 @@ -184,7 +184,7 @@ @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 @@ // 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 @@ } 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);