emul/src/main/java/java/lang/Math.java
changeset 104 1376481f15e7
parent 84 d65b3a2fbfaf
child 132 2377bb30dd1b
     1.1 --- a/emul/src/main/java/java/lang/Math.java	Sun Sep 30 18:29:37 2012 -0700
     1.2 +++ b/emul/src/main/java/java/lang/Math.java	Tue Oct 16 11:55:56 2012 +0200
     1.3 @@ -25,6 +25,8 @@
     1.4  
     1.5  package java.lang;
     1.6  
     1.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
     1.8 +
     1.9  
    1.10  /**
    1.11   * The class {@code Math} contains methods for performing basic
    1.12 @@ -813,9 +815,6 @@
    1.13          return (a >= b) ? a : b;
    1.14      }
    1.15  
    1.16 -    private static long negativeZeroFloatBits = Float.floatToIntBits(-0.0f);
    1.17 -    private static long negativeZeroDoubleBits = Double.doubleToLongBits(-0.0d);
    1.18 -
    1.19      /**
    1.20       * Returns the greater of two {@code float} values.  That is,
    1.21       * the result is the argument closer to positive infinity. If the
    1.22 @@ -830,13 +829,11 @@
    1.23       * @param   b   another argument.
    1.24       * @return  the larger of {@code a} and {@code b}.
    1.25       */
    1.26 +    @JavaScriptBody(args={"a", "b"},
    1.27 +        body="return Math.max(a,b);"
    1.28 +    )
    1.29      public static float max(float a, float b) {
    1.30 -        if (a != a) return a;   // a is NaN
    1.31 -        if ((a == 0.0f) && (b == 0.0f)
    1.32 -            && (Float.floatToIntBits(a) == negativeZeroFloatBits)) {
    1.33 -            return b;
    1.34 -        }
    1.35 -        return (a >= b) ? a : b;
    1.36 +        throw new UnsupportedOperationException();
    1.37      }
    1.38  
    1.39      /**
    1.40 @@ -853,13 +850,11 @@
    1.41       * @param   b   another argument.
    1.42       * @return  the larger of {@code a} and {@code b}.
    1.43       */
    1.44 +    @JavaScriptBody(args={"a", "b"},
    1.45 +        body="return Math.max(a,b);"
    1.46 +    )
    1.47      public static double max(double a, double b) {
    1.48 -        if (a != a) return a;   // a is NaN
    1.49 -        if ((a == 0.0d) && (b == 0.0d)
    1.50 -            && (Double.doubleToLongBits(a) == negativeZeroDoubleBits)) {
    1.51 -            return b;
    1.52 -        }
    1.53 -        return (a >= b) ? a : b;
    1.54 +        throw new UnsupportedOperationException();
    1.55      }
    1.56  
    1.57      /**
    1.58 @@ -904,13 +899,11 @@
    1.59       * @param   b   another argument.
    1.60       * @return  the smaller of {@code a} and {@code b}.
    1.61       */
    1.62 +    @JavaScriptBody(args={"a", "b"},
    1.63 +        body="return Math.min(a,b);"
    1.64 +    )
    1.65      public static float min(float a, float b) {
    1.66 -        if (a != a) return a;   // a is NaN
    1.67 -        if ((a == 0.0f) && (b == 0.0f)
    1.68 -            && (Float.floatToIntBits(b) == negativeZeroFloatBits)) {
    1.69 -            return b;
    1.70 -        }
    1.71 -        return (a <= b) ? a : b;
    1.72 +        throw new UnsupportedOperationException();
    1.73      }
    1.74  
    1.75      /**
    1.76 @@ -927,13 +920,11 @@
    1.77       * @param   b   another argument.
    1.78       * @return  the smaller of {@code a} and {@code b}.
    1.79       */
    1.80 +    @JavaScriptBody(args={"a", "b"},
    1.81 +        body="return Math.min(a,b);"
    1.82 +    )
    1.83      public static double min(double a, double b) {
    1.84 -        if (a != a) return a;   // a is NaN
    1.85 -        if ((a == 0.0d) && (b == 0.0d)
    1.86 -            && (Double.doubleToLongBits(b) == negativeZeroDoubleBits)) {
    1.87 -            return b;
    1.88 -        }
    1.89 -        return (a <= b) ? a : b;
    1.90 +        throw new UnsupportedOperationException();
    1.91      }
    1.92  
    1.93      /**