emul/src/main/java/java/lang/Math.java
changeset 132 2377bb30dd1b
parent 104 1376481f15e7
child 551 ca781bc82662
     1.1 --- a/emul/src/main/java/java/lang/Math.java	Tue Oct 16 11:55:56 2012 +0200
     1.2 +++ b/emul/src/main/java/java/lang/Math.java	Tue Oct 30 23:33:29 2012 +0100
     1.3 @@ -118,8 +118,9 @@
     1.4       * @param   a   an angle, in radians.
     1.5       * @return  the sine of the argument.
     1.6       */
     1.7 +    @JavaScriptBody(args="a", body="return Math.sin(a);")
     1.8      public static double sin(double a) {
     1.9 -        return StrictMath.sin(a); // default impl. delegates to StrictMath
    1.10 +        throw new UnsupportedOperationException();
    1.11      }
    1.12  
    1.13      /**
    1.14 @@ -133,8 +134,9 @@
    1.15       * @param   a   an angle, in radians.
    1.16       * @return  the cosine of the argument.
    1.17       */
    1.18 +    @JavaScriptBody(args="a", body="return Math.cos(a);")
    1.19      public static double cos(double a) {
    1.20 -        return StrictMath.cos(a); // default impl. delegates to StrictMath
    1.21 +        throw new UnsupportedOperationException();
    1.22      }
    1.23  
    1.24      /**
    1.25 @@ -150,8 +152,9 @@
    1.26       * @param   a   an angle, in radians.
    1.27       * @return  the tangent of the argument.
    1.28       */
    1.29 +    @JavaScriptBody(args="a", body="return Math.tan(a);")
    1.30      public static double tan(double a) {
    1.31 -        return StrictMath.tan(a); // default impl. delegates to StrictMath
    1.32 +        throw new UnsupportedOperationException();
    1.33      }
    1.34  
    1.35      /**
    1.36 @@ -168,8 +171,9 @@
    1.37       * @param   a   the value whose arc sine is to be returned.
    1.38       * @return  the arc sine of the argument.
    1.39       */
    1.40 +    @JavaScriptBody(args="a", body="return Math.asin(a);")
    1.41      public static double asin(double a) {
    1.42 -        return StrictMath.asin(a); // default impl. delegates to StrictMath
    1.43 +        throw new UnsupportedOperationException();
    1.44      }
    1.45  
    1.46      /**
    1.47 @@ -184,8 +188,9 @@
    1.48       * @param   a   the value whose arc cosine is to be returned.
    1.49       * @return  the arc cosine of the argument.
    1.50       */
    1.51 +    @JavaScriptBody(args="a", body="return Math.acos(a);")
    1.52      public static double acos(double a) {
    1.53 -        return StrictMath.acos(a); // default impl. delegates to StrictMath
    1.54 +        throw new UnsupportedOperationException();
    1.55      }
    1.56  
    1.57      /**
    1.58 @@ -201,8 +206,9 @@
    1.59       * @param   a   the value whose arc tangent is to be returned.
    1.60       * @return  the arc tangent of the argument.
    1.61       */
    1.62 +    @JavaScriptBody(args="a", body="return Math.atan(a);")
    1.63      public static double atan(double a) {
    1.64 -        return StrictMath.atan(a); // default impl. delegates to StrictMath
    1.65 +        throw new UnsupportedOperationException();
    1.66      }
    1.67  
    1.68      /**
    1.69 @@ -251,8 +257,9 @@
    1.70       * @return  the value <i>e</i><sup>{@code a}</sup>,
    1.71       *          where <i>e</i> is the base of the natural logarithms.
    1.72       */
    1.73 +    @JavaScriptBody(args="a", body="return Math.exp(a);")
    1.74      public static double exp(double a) {
    1.75 -        return StrictMath.exp(a); // default impl. delegates to StrictMath
    1.76 +        throw new UnsupportedOperationException();
    1.77      }
    1.78  
    1.79      /**
    1.80 @@ -272,8 +279,9 @@
    1.81       * @return  the value ln&nbsp;{@code a}, the natural logarithm of
    1.82       *          {@code a}.
    1.83       */
    1.84 +    @JavaScriptBody(args="a", body="return Math.log(a);")
    1.85      public static double log(double a) {
    1.86 -        return StrictMath.log(a); // default impl. delegates to StrictMath
    1.87 +        throw new UnsupportedOperationException();
    1.88      }
    1.89  
    1.90      /**
    1.91 @@ -297,8 +305,9 @@
    1.92       * @return  the base 10 logarithm of  {@code a}.
    1.93       * @since 1.5
    1.94       */
    1.95 +    @JavaScriptBody(args="a", body="return Math.log(a) / Math.LN10;")
    1.96      public static double log10(double a) {
    1.97 -        return StrictMath.log10(a); // default impl. delegates to StrictMath
    1.98 +        throw new UnsupportedOperationException();
    1.99      }
   1.100  
   1.101      /**
   1.102 @@ -318,69 +327,9 @@
   1.103       * @return  the positive square root of {@code a}.
   1.104       *          If the argument is NaN or less than zero, the result is NaN.
   1.105       */
   1.106 +    @JavaScriptBody(args="a", body="return Math.sqrt(a);")
   1.107      public static double sqrt(double a) {
   1.108 -        return StrictMath.sqrt(a); // default impl. delegates to StrictMath
   1.109 -                                   // Note that hardware sqrt instructions
   1.110 -                                   // frequently can be directly used by JITs
   1.111 -                                   // and should be much faster than doing
   1.112 -                                   // Math.sqrt in software.
   1.113 -    }
   1.114 -
   1.115 -
   1.116 -    /**
   1.117 -     * Returns the cube root of a {@code double} value.  For
   1.118 -     * positive finite {@code x}, {@code cbrt(-x) ==
   1.119 -     * -cbrt(x)}; that is, the cube root of a negative value is
   1.120 -     * the negative of the cube root of that value's magnitude.
   1.121 -     *
   1.122 -     * Special cases:
   1.123 -     *
   1.124 -     * <ul>
   1.125 -     *
   1.126 -     * <li>If the argument is NaN, then the result is NaN.
   1.127 -     *
   1.128 -     * <li>If the argument is infinite, then the result is an infinity
   1.129 -     * with the same sign as the argument.
   1.130 -     *
   1.131 -     * <li>If the argument is zero, then the result is a zero with the
   1.132 -     * same sign as the argument.
   1.133 -     *
   1.134 -     * </ul>
   1.135 -     *
   1.136 -     * <p>The computed result must be within 1 ulp of the exact result.
   1.137 -     *
   1.138 -     * @param   a   a value.
   1.139 -     * @return  the cube root of {@code a}.
   1.140 -     * @since 1.5
   1.141 -     */
   1.142 -    public static double cbrt(double a) {
   1.143 -        return StrictMath.cbrt(a);
   1.144 -    }
   1.145 -
   1.146 -    /**
   1.147 -     * Computes the remainder operation on two arguments as prescribed
   1.148 -     * by the IEEE 754 standard.
   1.149 -     * The remainder value is mathematically equal to
   1.150 -     * <code>f1&nbsp;-&nbsp;f2</code>&nbsp;&times;&nbsp;<i>n</i>,
   1.151 -     * where <i>n</i> is the mathematical integer closest to the exact
   1.152 -     * mathematical value of the quotient {@code f1/f2}, and if two
   1.153 -     * mathematical integers are equally close to {@code f1/f2},
   1.154 -     * then <i>n</i> is the integer that is even. If the remainder is
   1.155 -     * zero, its sign is the same as the sign of the first argument.
   1.156 -     * Special cases:
   1.157 -     * <ul><li>If either argument is NaN, or the first argument is infinite,
   1.158 -     * or the second argument is positive zero or negative zero, then the
   1.159 -     * result is NaN.
   1.160 -     * <li>If the first argument is finite and the second argument is
   1.161 -     * infinite, then the result is the same as the first argument.</ul>
   1.162 -     *
   1.163 -     * @param   f1   the dividend.
   1.164 -     * @param   f2   the divisor.
   1.165 -     * @return  the remainder when {@code f1} is divided by
   1.166 -     *          {@code f2}.
   1.167 -     */
   1.168 -    public static double IEEEremainder(double f1, double f2) {
   1.169 -        return StrictMath.IEEEremainder(f1, f2); // delegate to StrictMath
   1.170 +        throw new UnsupportedOperationException();
   1.171      }
   1.172  
   1.173      /**
   1.174 @@ -402,8 +351,9 @@
   1.175       *          floating-point value that is greater than or equal to
   1.176       *          the argument and is equal to a mathematical integer.
   1.177       */
   1.178 +    @JavaScriptBody(args="a", body="return Math.ceil(a);")
   1.179      public static double ceil(double a) {
   1.180 -        return StrictMath.ceil(a); // default impl. delegates to StrictMath
   1.181 +        throw new UnsupportedOperationException();
   1.182      }
   1.183  
   1.184      /**
   1.185 @@ -421,27 +371,9 @@
   1.186       *          floating-point value that less than or equal to the argument
   1.187       *          and is equal to a mathematical integer.
   1.188       */
   1.189 +    @JavaScriptBody(args="a", body="return Math.floor(a);")
   1.190      public static double floor(double a) {
   1.191 -        return StrictMath.floor(a); // default impl. delegates to StrictMath
   1.192 -    }
   1.193 -
   1.194 -    /**
   1.195 -     * Returns the {@code double} value that is closest in value
   1.196 -     * to the argument and is equal to a mathematical integer. If two
   1.197 -     * {@code double} values that are mathematical integers are
   1.198 -     * equally close, the result is the integer value that is
   1.199 -     * even. Special cases:
   1.200 -     * <ul><li>If the argument value is already equal to a mathematical
   1.201 -     * integer, then the result is the same as the argument.
   1.202 -     * <li>If the argument is NaN or an infinity or positive zero or negative
   1.203 -     * zero, then the result is the same as the argument.</ul>
   1.204 -     *
   1.205 -     * @param   a   a {@code double} value.
   1.206 -     * @return  the closest floating-point value to {@code a} that is
   1.207 -     *          equal to a mathematical integer.
   1.208 -     */
   1.209 -    public static double rint(double a) {
   1.210 -        return StrictMath.rint(a); // default impl. delegates to StrictMath
   1.211 +        throw new UnsupportedOperationException();
   1.212      }
   1.213  
   1.214      /**
   1.215 @@ -496,8 +428,9 @@
   1.216       *          in polar coordinates that corresponds to the point
   1.217       *          (<i>x</i>,&nbsp;<i>y</i>) in Cartesian coordinates.
   1.218       */
   1.219 +    @JavaScriptBody(args={"y", "x"}, body="return Math.atan2(y, x);")
   1.220      public static double atan2(double y, double x) {
   1.221 -        return StrictMath.atan2(y, x); // default impl. delegates to StrictMath
   1.222 +        throw new UnsupportedOperationException();
   1.223      }
   1.224  
   1.225      /**
   1.226 @@ -623,8 +556,9 @@
   1.227       * @param   b   the exponent.
   1.228       * @return  the value {@code a}<sup>{@code b}</sup>.
   1.229       */
   1.230 +    @JavaScriptBody(args={"a", "b"}, body="return Math.pow(a, b);")
   1.231      public static double pow(double a, double b) {
   1.232 -        return StrictMath.pow(a, b); // default impl. delegates to StrictMath
   1.233 +        throw new UnsupportedOperationException();
   1.234      }
   1.235  
   1.236      /**
   1.237 @@ -647,11 +581,9 @@
   1.238       * @see     java.lang.Integer#MAX_VALUE
   1.239       * @see     java.lang.Integer#MIN_VALUE
   1.240       */
   1.241 +    @JavaScriptBody(args="a", body="return Math.round(a);")
   1.242      public static int round(float a) {
   1.243 -        if (a != 0x1.fffffep-2f) // greatest float value less than 0.5
   1.244 -            return (int)floor(a + 0.5f);
   1.245 -        else
   1.246 -            return 0;
   1.247 +        throw new UnsupportedOperationException();
   1.248      }
   1.249  
   1.250      /**
   1.251 @@ -674,11 +606,9 @@
   1.252       * @see     java.lang.Long#MAX_VALUE
   1.253       * @see     java.lang.Long#MIN_VALUE
   1.254       */
   1.255 +    @JavaScriptBody(args="a", body="return Math.round(a);")
   1.256      public static long round(double a) {
   1.257 -        if (a != 0x1.fffffffffffffp-2) // greatest double value less than 0.5
   1.258 -            return (long)floor(a + 0.5d);
   1.259 -        else
   1.260 -            return 0;
   1.261 +        throw new UnsupportedOperationException();
   1.262      }
   1.263  
   1.264  //    private static Random randomNumberGenerator;
   1.265 @@ -1024,207 +954,6 @@
   1.266  //    }
   1.267  
   1.268      /**
   1.269 -     * Returns the hyperbolic sine of a {@code double} value.
   1.270 -     * The hyperbolic sine of <i>x</i> is defined to be
   1.271 -     * (<i>e<sup>x</sup>&nbsp;-&nbsp;e<sup>-x</sup></i>)/2
   1.272 -     * where <i>e</i> is {@linkplain Math#E Euler's number}.
   1.273 -     *
   1.274 -     * <p>Special cases:
   1.275 -     * <ul>
   1.276 -     *
   1.277 -     * <li>If the argument is NaN, then the result is NaN.
   1.278 -     *
   1.279 -     * <li>If the argument is infinite, then the result is an infinity
   1.280 -     * with the same sign as the argument.
   1.281 -     *
   1.282 -     * <li>If the argument is zero, then the result is a zero with the
   1.283 -     * same sign as the argument.
   1.284 -     *
   1.285 -     * </ul>
   1.286 -     *
   1.287 -     * <p>The computed result must be within 2.5 ulps of the exact result.
   1.288 -     *
   1.289 -     * @param   x The number whose hyperbolic sine is to be returned.
   1.290 -     * @return  The hyperbolic sine of {@code x}.
   1.291 -     * @since 1.5
   1.292 -     */
   1.293 -    public static double sinh(double x) {
   1.294 -        return StrictMath.sinh(x);
   1.295 -    }
   1.296 -
   1.297 -    /**
   1.298 -     * Returns the hyperbolic cosine of a {@code double} value.
   1.299 -     * The hyperbolic cosine of <i>x</i> is defined to be
   1.300 -     * (<i>e<sup>x</sup>&nbsp;+&nbsp;e<sup>-x</sup></i>)/2
   1.301 -     * where <i>e</i> is {@linkplain Math#E Euler's number}.
   1.302 -     *
   1.303 -     * <p>Special cases:
   1.304 -     * <ul>
   1.305 -     *
   1.306 -     * <li>If the argument is NaN, then the result is NaN.
   1.307 -     *
   1.308 -     * <li>If the argument is infinite, then the result is positive
   1.309 -     * infinity.
   1.310 -     *
   1.311 -     * <li>If the argument is zero, then the result is {@code 1.0}.
   1.312 -     *
   1.313 -     * </ul>
   1.314 -     *
   1.315 -     * <p>The computed result must be within 2.5 ulps of the exact result.
   1.316 -     *
   1.317 -     * @param   x The number whose hyperbolic cosine is to be returned.
   1.318 -     * @return  The hyperbolic cosine of {@code x}.
   1.319 -     * @since 1.5
   1.320 -     */
   1.321 -    public static double cosh(double x) {
   1.322 -        return StrictMath.cosh(x);
   1.323 -    }
   1.324 -
   1.325 -    /**
   1.326 -     * Returns the hyperbolic tangent of a {@code double} value.
   1.327 -     * The hyperbolic tangent of <i>x</i> is defined to be
   1.328 -     * (<i>e<sup>x</sup>&nbsp;-&nbsp;e<sup>-x</sup></i>)/(<i>e<sup>x</sup>&nbsp;+&nbsp;e<sup>-x</sup></i>),
   1.329 -     * in other words, {@linkplain Math#sinh
   1.330 -     * sinh(<i>x</i>)}/{@linkplain Math#cosh cosh(<i>x</i>)}.  Note
   1.331 -     * that the absolute value of the exact tanh is always less than
   1.332 -     * 1.
   1.333 -     *
   1.334 -     * <p>Special cases:
   1.335 -     * <ul>
   1.336 -     *
   1.337 -     * <li>If the argument is NaN, then the result is NaN.
   1.338 -     *
   1.339 -     * <li>If the argument is zero, then the result is a zero with the
   1.340 -     * same sign as the argument.
   1.341 -     *
   1.342 -     * <li>If the argument is positive infinity, then the result is
   1.343 -     * {@code +1.0}.
   1.344 -     *
   1.345 -     * <li>If the argument is negative infinity, then the result is
   1.346 -     * {@code -1.0}.
   1.347 -     *
   1.348 -     * </ul>
   1.349 -     *
   1.350 -     * <p>The computed result must be within 2.5 ulps of the exact result.
   1.351 -     * The result of {@code tanh} for any finite input must have
   1.352 -     * an absolute value less than or equal to 1.  Note that once the
   1.353 -     * exact result of tanh is within 1/2 of an ulp of the limit value
   1.354 -     * of &plusmn;1, correctly signed &plusmn;{@code 1.0} should
   1.355 -     * be returned.
   1.356 -     *
   1.357 -     * @param   x The number whose hyperbolic tangent is to be returned.
   1.358 -     * @return  The hyperbolic tangent of {@code x}.
   1.359 -     * @since 1.5
   1.360 -     */
   1.361 -    public static double tanh(double x) {
   1.362 -        return StrictMath.tanh(x);
   1.363 -    }
   1.364 -
   1.365 -    /**
   1.366 -     * Returns sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)
   1.367 -     * without intermediate overflow or underflow.
   1.368 -     *
   1.369 -     * <p>Special cases:
   1.370 -     * <ul>
   1.371 -     *
   1.372 -     * <li> If either argument is infinite, then the result
   1.373 -     * is positive infinity.
   1.374 -     *
   1.375 -     * <li> If either argument is NaN and neither argument is infinite,
   1.376 -     * then the result is NaN.
   1.377 -     *
   1.378 -     * </ul>
   1.379 -     *
   1.380 -     * <p>The computed result must be within 1 ulp of the exact
   1.381 -     * result.  If one parameter is held constant, the results must be
   1.382 -     * semi-monotonic in the other parameter.
   1.383 -     *
   1.384 -     * @param x a value
   1.385 -     * @param y a value
   1.386 -     * @return sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)
   1.387 -     * without intermediate overflow or underflow
   1.388 -     * @since 1.5
   1.389 -     */
   1.390 -    public static double hypot(double x, double y) {
   1.391 -        return StrictMath.hypot(x, y);
   1.392 -    }
   1.393 -
   1.394 -    /**
   1.395 -     * Returns <i>e</i><sup>x</sup>&nbsp;-1.  Note that for values of
   1.396 -     * <i>x</i> near 0, the exact sum of
   1.397 -     * {@code expm1(x)}&nbsp;+&nbsp;1 is much closer to the true
   1.398 -     * result of <i>e</i><sup>x</sup> than {@code exp(x)}.
   1.399 -     *
   1.400 -     * <p>Special cases:
   1.401 -     * <ul>
   1.402 -     * <li>If the argument is NaN, the result is NaN.
   1.403 -     *
   1.404 -     * <li>If the argument is positive infinity, then the result is
   1.405 -     * positive infinity.
   1.406 -     *
   1.407 -     * <li>If the argument is negative infinity, then the result is
   1.408 -     * -1.0.
   1.409 -     *
   1.410 -     * <li>If the argument is zero, then the result is a zero with the
   1.411 -     * same sign as the argument.
   1.412 -     *
   1.413 -     * </ul>
   1.414 -     *
   1.415 -     * <p>The computed result must be within 1 ulp of the exact result.
   1.416 -     * Results must be semi-monotonic.  The result of
   1.417 -     * {@code expm1} for any finite input must be greater than or
   1.418 -     * equal to {@code -1.0}.  Note that once the exact result of
   1.419 -     * <i>e</i><sup>{@code x}</sup>&nbsp;-&nbsp;1 is within 1/2
   1.420 -     * ulp of the limit value -1, {@code -1.0} should be
   1.421 -     * returned.
   1.422 -     *
   1.423 -     * @param   x   the exponent to raise <i>e</i> to in the computation of
   1.424 -     *              <i>e</i><sup>{@code x}</sup>&nbsp;-1.
   1.425 -     * @return  the value <i>e</i><sup>{@code x}</sup>&nbsp;-&nbsp;1.
   1.426 -     * @since 1.5
   1.427 -     */
   1.428 -    public static double expm1(double x) {
   1.429 -        return StrictMath.expm1(x);
   1.430 -    }
   1.431 -
   1.432 -    /**
   1.433 -     * Returns the natural logarithm of the sum of the argument and 1.
   1.434 -     * Note that for small values {@code x}, the result of
   1.435 -     * {@code log1p(x)} is much closer to the true result of ln(1
   1.436 -     * + {@code x}) than the floating-point evaluation of
   1.437 -     * {@code log(1.0+x)}.
   1.438 -     *
   1.439 -     * <p>Special cases:
   1.440 -     *
   1.441 -     * <ul>
   1.442 -     *
   1.443 -     * <li>If the argument is NaN or less than -1, then the result is
   1.444 -     * NaN.
   1.445 -     *
   1.446 -     * <li>If the argument is positive infinity, then the result is
   1.447 -     * positive infinity.
   1.448 -     *
   1.449 -     * <li>If the argument is negative one, then the result is
   1.450 -     * negative infinity.
   1.451 -     *
   1.452 -     * <li>If the argument is zero, then the result is a zero with the
   1.453 -     * same sign as the argument.
   1.454 -     *
   1.455 -     * </ul>
   1.456 -     *
   1.457 -     * <p>The computed result must be within 1 ulp of the exact result.
   1.458 -     * Results must be semi-monotonic.
   1.459 -     *
   1.460 -     * @param   x   a value
   1.461 -     * @return the value ln({@code x}&nbsp;+&nbsp;1), the natural
   1.462 -     * log of {@code x}&nbsp;+&nbsp;1
   1.463 -     * @since 1.5
   1.464 -     */
   1.465 -    public static double log1p(double x) {
   1.466 -        return StrictMath.log1p(x);
   1.467 -    }
   1.468 -
   1.469 -    /**
   1.470       * Returns the first floating-point argument with the sign of the
   1.471       * second floating-point argument.  Note that unlike the {@link
   1.472       * StrictMath#copySign(double, double) StrictMath.copySign}