1.1 --- a/emul/src/main/java/java/lang/Math.java Tue Oct 30 22:59:31 2012 +0100
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 {@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 - f2</code> × <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>, <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> - 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> + 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> - e<sup>-x</sup></i>)/(<i>e<sup>x</sup> + 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 ±1, correctly signed ±{@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> +<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> +<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> -1. Note that for values of
1.396 - * <i>x</i> near 0, the exact sum of
1.397 - * {@code expm1(x)} + 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> - 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> -1.
1.425 - * @return the value <i>e</i><sup>{@code x}</sup> - 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} + 1), the natural
1.462 - * log of {@code x} + 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}
2.1 --- a/emul/src/main/java/java/lang/StrictMath.java Tue Oct 30 22:59:31 2012 +0100
2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
2.3 @@ -1,1457 +0,0 @@
2.4 -/*
2.5 - * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2.7 - *
2.8 - * This code is free software; you can redistribute it and/or modify it
2.9 - * under the terms of the GNU General Public License version 2 only, as
2.10 - * published by the Free Software Foundation. Oracle designates this
2.11 - * particular file as subject to the "Classpath" exception as provided
2.12 - * by Oracle in the LICENSE file that accompanied this code.
2.13 - *
2.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
2.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2.17 - * version 2 for more details (a copy is included in the LICENSE file that
2.18 - * accompanied this code).
2.19 - *
2.20 - * You should have received a copy of the GNU General Public License version
2.21 - * 2 along with this work; if not, write to the Free Software Foundation,
2.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2.23 - *
2.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2.25 - * or visit www.oracle.com if you need additional information or have any
2.26 - * questions.
2.27 - */
2.28 -
2.29 -package java.lang;
2.30 -
2.31 -/**
2.32 - * The class {@code StrictMath} contains methods for performing basic
2.33 - * numeric operations such as the elementary exponential, logarithm,
2.34 - * square root, and trigonometric functions.
2.35 - *
2.36 - * <p>To help ensure portability of Java programs, the definitions of
2.37 - * some of the numeric functions in this package require that they
2.38 - * produce the same results as certain published algorithms. These
2.39 - * algorithms are available from the well-known network library
2.40 - * {@code netlib} as the package "Freely Distributable Math
2.41 - * Library," <a
2.42 - * href="ftp://ftp.netlib.org/fdlibm.tar">{@code fdlibm}</a>. These
2.43 - * algorithms, which are written in the C programming language, are
2.44 - * then to be understood as executed with all floating-point
2.45 - * operations following the rules of Java floating-point arithmetic.
2.46 - *
2.47 - * <p>The Java math library is defined with respect to
2.48 - * {@code fdlibm} version 5.3. Where {@code fdlibm} provides
2.49 - * more than one definition for a function (such as
2.50 - * {@code acos}), use the "IEEE 754 core function" version
2.51 - * (residing in a file whose name begins with the letter
2.52 - * {@code e}). The methods which require {@code fdlibm}
2.53 - * semantics are {@code sin}, {@code cos}, {@code tan},
2.54 - * {@code asin}, {@code acos}, {@code atan},
2.55 - * {@code exp}, {@code log}, {@code log10},
2.56 - * {@code cbrt}, {@code atan2}, {@code pow},
2.57 - * {@code sinh}, {@code cosh}, {@code tanh},
2.58 - * {@code hypot}, {@code expm1}, and {@code log1p}.
2.59 - *
2.60 - * @author unascribed
2.61 - * @author Joseph D. Darcy
2.62 - * @since 1.3
2.63 - */
2.64 -
2.65 -public final class StrictMath {
2.66 -
2.67 - /**
2.68 - * Don't let anyone instantiate this class.
2.69 - */
2.70 - private StrictMath() {}
2.71 -
2.72 - /**
2.73 - * The {@code double} value that is closer than any other to
2.74 - * <i>e</i>, the base of the natural logarithms.
2.75 - */
2.76 - public static final double E = 2.7182818284590452354;
2.77 -
2.78 - /**
2.79 - * The {@code double} value that is closer than any other to
2.80 - * <i>pi</i>, the ratio of the circumference of a circle to its
2.81 - * diameter.
2.82 - */
2.83 - public static final double PI = 3.14159265358979323846;
2.84 -
2.85 - /**
2.86 - * Returns the trigonometric sine of an angle. Special cases:
2.87 - * <ul><li>If the argument is NaN or an infinity, then the
2.88 - * result is NaN.
2.89 - * <li>If the argument is zero, then the result is a zero with the
2.90 - * same sign as the argument.</ul>
2.91 - *
2.92 - * @param a an angle, in radians.
2.93 - * @return the sine of the argument.
2.94 - */
2.95 - public static native double sin(double a);
2.96 -
2.97 - /**
2.98 - * Returns the trigonometric cosine of an angle. Special cases:
2.99 - * <ul><li>If the argument is NaN or an infinity, then the
2.100 - * result is NaN.</ul>
2.101 - *
2.102 - * @param a an angle, in radians.
2.103 - * @return the cosine of the argument.
2.104 - */
2.105 - public static native double cos(double a);
2.106 -
2.107 - /**
2.108 - * Returns the trigonometric tangent of an angle. Special cases:
2.109 - * <ul><li>If the argument is NaN or an infinity, then the result
2.110 - * is NaN.
2.111 - * <li>If the argument is zero, then the result is a zero with the
2.112 - * same sign as the argument.</ul>
2.113 - *
2.114 - * @param a an angle, in radians.
2.115 - * @return the tangent of the argument.
2.116 - */
2.117 - public static native double tan(double a);
2.118 -
2.119 - /**
2.120 - * Returns the arc sine of a value; the returned angle is in the
2.121 - * range -<i>pi</i>/2 through <i>pi</i>/2. Special cases:
2.122 - * <ul><li>If the argument is NaN or its absolute value is greater
2.123 - * than 1, then the result is NaN.
2.124 - * <li>If the argument is zero, then the result is a zero with the
2.125 - * same sign as the argument.</ul>
2.126 - *
2.127 - * @param a the value whose arc sine is to be returned.
2.128 - * @return the arc sine of the argument.
2.129 - */
2.130 - public static native double asin(double a);
2.131 -
2.132 - /**
2.133 - * Returns the arc cosine of a value; the returned angle is in the
2.134 - * range 0.0 through <i>pi</i>. Special case:
2.135 - * <ul><li>If the argument is NaN or its absolute value is greater
2.136 - * than 1, then the result is NaN.</ul>
2.137 - *
2.138 - * @param a the value whose arc cosine is to be returned.
2.139 - * @return the arc cosine of the argument.
2.140 - */
2.141 - public static native double acos(double a);
2.142 -
2.143 - /**
2.144 - * Returns the arc tangent of a value; the returned angle is in the
2.145 - * range -<i>pi</i>/2 through <i>pi</i>/2. Special cases:
2.146 - * <ul><li>If the argument is NaN, then the result is NaN.
2.147 - * <li>If the argument is zero, then the result is a zero with the
2.148 - * same sign as the argument.</ul>
2.149 - *
2.150 - * @param a the value whose arc tangent is to be returned.
2.151 - * @return the arc tangent of the argument.
2.152 - */
2.153 - public static native double atan(double a);
2.154 -
2.155 - /**
2.156 - * Converts an angle measured in degrees to an approximately
2.157 - * equivalent angle measured in radians. The conversion from
2.158 - * degrees to radians is generally inexact.
2.159 - *
2.160 - * @param angdeg an angle, in degrees
2.161 - * @return the measurement of the angle {@code angdeg}
2.162 - * in radians.
2.163 - */
2.164 - public static strictfp double toRadians(double angdeg) {
2.165 - return angdeg / 180.0 * PI;
2.166 - }
2.167 -
2.168 - /**
2.169 - * Converts an angle measured in radians to an approximately
2.170 - * equivalent angle measured in degrees. The conversion from
2.171 - * radians to degrees is generally inexact; users should
2.172 - * <i>not</i> expect {@code cos(toRadians(90.0))} to exactly
2.173 - * equal {@code 0.0}.
2.174 - *
2.175 - * @param angrad an angle, in radians
2.176 - * @return the measurement of the angle {@code angrad}
2.177 - * in degrees.
2.178 - */
2.179 - public static strictfp double toDegrees(double angrad) {
2.180 - return angrad * 180.0 / PI;
2.181 - }
2.182 -
2.183 - /**
2.184 - * Returns Euler's number <i>e</i> raised to the power of a
2.185 - * {@code double} value. Special cases:
2.186 - * <ul><li>If the argument is NaN, the result is NaN.
2.187 - * <li>If the argument is positive infinity, then the result is
2.188 - * positive infinity.
2.189 - * <li>If the argument is negative infinity, then the result is
2.190 - * positive zero.</ul>
2.191 - *
2.192 - * @param a the exponent to raise <i>e</i> to.
2.193 - * @return the value <i>e</i><sup>{@code a}</sup>,
2.194 - * where <i>e</i> is the base of the natural logarithms.
2.195 - */
2.196 - public static native double exp(double a);
2.197 -
2.198 - /**
2.199 - * Returns the natural logarithm (base <i>e</i>) of a {@code double}
2.200 - * value. Special cases:
2.201 - * <ul><li>If the argument is NaN or less than zero, then the result
2.202 - * is NaN.
2.203 - * <li>If the argument is positive infinity, then the result is
2.204 - * positive infinity.
2.205 - * <li>If the argument is positive zero or negative zero, then the
2.206 - * result is negative infinity.</ul>
2.207 - *
2.208 - * @param a a value
2.209 - * @return the value ln {@code a}, the natural logarithm of
2.210 - * {@code a}.
2.211 - */
2.212 - public static native double log(double a);
2.213 -
2.214 -
2.215 - /**
2.216 - * Returns the base 10 logarithm of a {@code double} value.
2.217 - * Special cases:
2.218 - *
2.219 - * <ul><li>If the argument is NaN or less than zero, then the result
2.220 - * is NaN.
2.221 - * <li>If the argument is positive infinity, then the result is
2.222 - * positive infinity.
2.223 - * <li>If the argument is positive zero or negative zero, then the
2.224 - * result is negative infinity.
2.225 - * <li> If the argument is equal to 10<sup><i>n</i></sup> for
2.226 - * integer <i>n</i>, then the result is <i>n</i>.
2.227 - * </ul>
2.228 - *
2.229 - * @param a a value
2.230 - * @return the base 10 logarithm of {@code a}.
2.231 - * @since 1.5
2.232 - */
2.233 - public static native double log10(double a);
2.234 -
2.235 - /**
2.236 - * Returns the correctly rounded positive square root of a
2.237 - * {@code double} value.
2.238 - * Special cases:
2.239 - * <ul><li>If the argument is NaN or less than zero, then the result
2.240 - * is NaN.
2.241 - * <li>If the argument is positive infinity, then the result is positive
2.242 - * infinity.
2.243 - * <li>If the argument is positive zero or negative zero, then the
2.244 - * result is the same as the argument.</ul>
2.245 - * Otherwise, the result is the {@code double} value closest to
2.246 - * the true mathematical square root of the argument value.
2.247 - *
2.248 - * @param a a value.
2.249 - * @return the positive square root of {@code a}.
2.250 - */
2.251 - public static native double sqrt(double a);
2.252 -
2.253 - /**
2.254 - * Returns the cube root of a {@code double} value. For
2.255 - * positive finite {@code x}, {@code cbrt(-x) ==
2.256 - * -cbrt(x)}; that is, the cube root of a negative value is
2.257 - * the negative of the cube root of that value's magnitude.
2.258 - * Special cases:
2.259 - *
2.260 - * <ul>
2.261 - *
2.262 - * <li>If the argument is NaN, then the result is NaN.
2.263 - *
2.264 - * <li>If the argument is infinite, then the result is an infinity
2.265 - * with the same sign as the argument.
2.266 - *
2.267 - * <li>If the argument is zero, then the result is a zero with the
2.268 - * same sign as the argument.
2.269 - *
2.270 - * </ul>
2.271 - *
2.272 - * @param a a value.
2.273 - * @return the cube root of {@code a}.
2.274 - * @since 1.5
2.275 - */
2.276 - public static native double cbrt(double a);
2.277 -
2.278 - /**
2.279 - * Computes the remainder operation on two arguments as prescribed
2.280 - * by the IEEE 754 standard.
2.281 - * The remainder value is mathematically equal to
2.282 - * <code>f1 - f2</code> × <i>n</i>,
2.283 - * where <i>n</i> is the mathematical integer closest to the exact
2.284 - * mathematical value of the quotient {@code f1/f2}, and if two
2.285 - * mathematical integers are equally close to {@code f1/f2},
2.286 - * then <i>n</i> is the integer that is even. If the remainder is
2.287 - * zero, its sign is the same as the sign of the first argument.
2.288 - * Special cases:
2.289 - * <ul><li>If either argument is NaN, or the first argument is infinite,
2.290 - * or the second argument is positive zero or negative zero, then the
2.291 - * result is NaN.
2.292 - * <li>If the first argument is finite and the second argument is
2.293 - * infinite, then the result is the same as the first argument.</ul>
2.294 - *
2.295 - * @param f1 the dividend.
2.296 - * @param f2 the divisor.
2.297 - * @return the remainder when {@code f1} is divided by
2.298 - * {@code f2}.
2.299 - */
2.300 - public static native double IEEEremainder(double f1, double f2);
2.301 -
2.302 - /**
2.303 - * Returns the smallest (closest to negative infinity)
2.304 - * {@code double} value that is greater than or equal to the
2.305 - * argument and is equal to a mathematical integer. Special cases:
2.306 - * <ul><li>If the argument value is already equal to a
2.307 - * mathematical integer, then the result is the same as the
2.308 - * argument. <li>If the argument is NaN or an infinity or
2.309 - * positive zero or negative zero, then the result is the same as
2.310 - * the argument. <li>If the argument value is less than zero but
2.311 - * greater than -1.0, then the result is negative zero.</ul> Note
2.312 - * that the value of {@code StrictMath.ceil(x)} is exactly the
2.313 - * value of {@code -StrictMath.floor(-x)}.
2.314 - *
2.315 - * @param a a value.
2.316 - * @return the smallest (closest to negative infinity)
2.317 - * floating-point value that is greater than or equal to
2.318 - * the argument and is equal to a mathematical integer.
2.319 - */
2.320 - public static double ceil(double a) {
2.321 - return floorOrCeil(a, -0.0, 1.0, 1.0);
2.322 - }
2.323 -
2.324 - /**
2.325 - * Returns the largest (closest to positive infinity)
2.326 - * {@code double} value that is less than or equal to the
2.327 - * argument and is equal to a mathematical integer. Special cases:
2.328 - * <ul><li>If the argument value is already equal to a
2.329 - * mathematical integer, then the result is the same as the
2.330 - * argument. <li>If the argument is NaN or an infinity or
2.331 - * positive zero or negative zero, then the result is the same as
2.332 - * the argument.</ul>
2.333 - *
2.334 - * @param a a value.
2.335 - * @return the largest (closest to positive infinity)
2.336 - * floating-point value that less than or equal to the argument
2.337 - * and is equal to a mathematical integer.
2.338 - */
2.339 - public static double floor(double a) {
2.340 - return floorOrCeil(a, -1.0, 0.0, -1.0);
2.341 - }
2.342 -
2.343 - /**
2.344 - * Internal method to share logic between floor and ceil.
2.345 - *
2.346 - * @param a the value to be floored or ceiled
2.347 - * @param negativeBoundary result for values in (-1, 0)
2.348 - * @param positiveBoundary result for values in (0, 1)
2.349 - * @param increment value to add when the argument is non-integral
2.350 - */
2.351 - private static double floorOrCeil(double a,
2.352 - double negativeBoundary,
2.353 - double positiveBoundary,
2.354 - double sign) {
2.355 - int exponent = getExponent(a);
2.356 -
2.357 - if (exponent < 0) {
2.358 - /*
2.359 - * Absolute value of argument is less than 1.
2.360 - * floorOrceil(-0.0) => -0.0
2.361 - * floorOrceil(+0.0) => +0.0
2.362 - */
2.363 - return ((a == 0.0) ? a :
2.364 - ( (a < 0.0) ? negativeBoundary : positiveBoundary) );
2.365 - } else if (exponent >= 52) {
2.366 - /*
2.367 - * Infinity, NaN, or a value so large it must be integral.
2.368 - */
2.369 - return a;
2.370 - }
2.371 - // Else the argument is either an integral value already XOR it
2.372 - // has to be rounded to one.
2.373 - assert exponent >= 0 && exponent <= 51;
2.374 -
2.375 - long doppel = Double.doubleToRawLongBits(a);
2.376 - long mask = 0; // DoubleConsts.SIGNIF_BIT_MASK >> exponent;
2.377 -
2.378 - if ( (mask & doppel) == 0L )
2.379 - return a; // integral value
2.380 - else {
2.381 - double result = Double.longBitsToDouble(doppel & (~mask));
2.382 - if (sign*a > 0.0)
2.383 - result = result + sign;
2.384 - return result;
2.385 - }
2.386 - }
2.387 -
2.388 - /**
2.389 - * Returns the {@code double} value that is closest in value
2.390 - * to the argument and is equal to a mathematical integer. If two
2.391 - * {@code double} values that are mathematical integers are
2.392 - * equally close to the value of the argument, the result is the
2.393 - * integer value that is even. Special cases:
2.394 - * <ul><li>If the argument value is already equal to a mathematical
2.395 - * integer, then the result is the same as the argument.
2.396 - * <li>If the argument is NaN or an infinity or positive zero or negative
2.397 - * zero, then the result is the same as the argument.</ul>
2.398 - *
2.399 - * @param a a value.
2.400 - * @return the closest floating-point value to {@code a} that is
2.401 - * equal to a mathematical integer.
2.402 - * @author Joseph D. Darcy
2.403 - */
2.404 - public static double rint(double a) {
2.405 - throw new UnsupportedOperationException();
2.406 - /*
2.407 - * If the absolute value of a is not less than 2^52, it
2.408 - * is either a finite integer (the double format does not have
2.409 - * enough significand bits for a number that large to have any
2.410 - * fractional portion), an infinity, or a NaN. In any of
2.411 - * these cases, rint of the argument is the argument.
2.412 - *
2.413 - * Otherwise, the sum (twoToThe52 + a ) will properly round
2.414 - * away any fractional portion of a since ulp(twoToThe52) ==
2.415 - * 1.0; subtracting out twoToThe52 from this sum will then be
2.416 - * exact and leave the rounded integer portion of a.
2.417 - *
2.418 - * This method does *not* need to be declared strictfp to get
2.419 - * fully reproducible results. Whether or not a method is
2.420 - * declared strictfp can only make a difference in the
2.421 - * returned result if some operation would overflow or
2.422 - * underflow with strictfp semantics. The operation
2.423 - * (twoToThe52 + a ) cannot overflow since large values of a
2.424 - * are screened out; the add cannot underflow since twoToThe52
2.425 - * is too large. The subtraction ((twoToThe52 + a ) -
2.426 - * twoToThe52) will be exact as discussed above and thus
2.427 - * cannot overflow or meaningfully underflow. Finally, the
2.428 - * last multiply in the return statement is by plus or minus
2.429 - * 1.0, which is exact too.
2.430 - */
2.431 -// double twoToThe52 = (double)(1L << 52); // 2^52
2.432 -// double sign = FpUtils.rawCopySign(1.0, a); // preserve sign info
2.433 -// a = Math.abs(a);
2.434 -//
2.435 -// if (a < twoToThe52) { // E_min <= ilogb(a) <= 51
2.436 -// a = ((twoToThe52 + a ) - twoToThe52);
2.437 -// }
2.438 -//
2.439 -// return sign * a; // restore original sign
2.440 - }
2.441 -
2.442 - /**
2.443 - * Returns the angle <i>theta</i> from the conversion of rectangular
2.444 - * coordinates ({@code x}, {@code y}) to polar
2.445 - * coordinates (r, <i>theta</i>).
2.446 - * This method computes the phase <i>theta</i> by computing an arc tangent
2.447 - * of {@code y/x} in the range of -<i>pi</i> to <i>pi</i>. Special
2.448 - * cases:
2.449 - * <ul><li>If either argument is NaN, then the result is NaN.
2.450 - * <li>If the first argument is positive zero and the second argument
2.451 - * is positive, or the first argument is positive and finite and the
2.452 - * second argument is positive infinity, then the result is positive
2.453 - * zero.
2.454 - * <li>If the first argument is negative zero and the second argument
2.455 - * is positive, or the first argument is negative and finite and the
2.456 - * second argument is positive infinity, then the result is negative zero.
2.457 - * <li>If the first argument is positive zero and the second argument
2.458 - * is negative, or the first argument is positive and finite and the
2.459 - * second argument is negative infinity, then the result is the
2.460 - * {@code double} value closest to <i>pi</i>.
2.461 - * <li>If the first argument is negative zero and the second argument
2.462 - * is negative, or the first argument is negative and finite and the
2.463 - * second argument is negative infinity, then the result is the
2.464 - * {@code double} value closest to -<i>pi</i>.
2.465 - * <li>If the first argument is positive and the second argument is
2.466 - * positive zero or negative zero, or the first argument is positive
2.467 - * infinity and the second argument is finite, then the result is the
2.468 - * {@code double} value closest to <i>pi</i>/2.
2.469 - * <li>If the first argument is negative and the second argument is
2.470 - * positive zero or negative zero, or the first argument is negative
2.471 - * infinity and the second argument is finite, then the result is the
2.472 - * {@code double} value closest to -<i>pi</i>/2.
2.473 - * <li>If both arguments are positive infinity, then the result is the
2.474 - * {@code double} value closest to <i>pi</i>/4.
2.475 - * <li>If the first argument is positive infinity and the second argument
2.476 - * is negative infinity, then the result is the {@code double}
2.477 - * value closest to 3*<i>pi</i>/4.
2.478 - * <li>If the first argument is negative infinity and the second argument
2.479 - * is positive infinity, then the result is the {@code double} value
2.480 - * closest to -<i>pi</i>/4.
2.481 - * <li>If both arguments are negative infinity, then the result is the
2.482 - * {@code double} value closest to -3*<i>pi</i>/4.</ul>
2.483 - *
2.484 - * @param y the ordinate coordinate
2.485 - * @param x the abscissa coordinate
2.486 - * @return the <i>theta</i> component of the point
2.487 - * (<i>r</i>, <i>theta</i>)
2.488 - * in polar coordinates that corresponds to the point
2.489 - * (<i>x</i>, <i>y</i>) in Cartesian coordinates.
2.490 - */
2.491 - public static native double atan2(double y, double x);
2.492 -
2.493 -
2.494 - /**
2.495 - * Returns the value of the first argument raised to the power of the
2.496 - * second argument. Special cases:
2.497 - *
2.498 - * <ul><li>If the second argument is positive or negative zero, then the
2.499 - * result is 1.0.
2.500 - * <li>If the second argument is 1.0, then the result is the same as the
2.501 - * first argument.
2.502 - * <li>If the second argument is NaN, then the result is NaN.
2.503 - * <li>If the first argument is NaN and the second argument is nonzero,
2.504 - * then the result is NaN.
2.505 - *
2.506 - * <li>If
2.507 - * <ul>
2.508 - * <li>the absolute value of the first argument is greater than 1
2.509 - * and the second argument is positive infinity, or
2.510 - * <li>the absolute value of the first argument is less than 1 and
2.511 - * the second argument is negative infinity,
2.512 - * </ul>
2.513 - * then the result is positive infinity.
2.514 - *
2.515 - * <li>If
2.516 - * <ul>
2.517 - * <li>the absolute value of the first argument is greater than 1 and
2.518 - * the second argument is negative infinity, or
2.519 - * <li>the absolute value of the
2.520 - * first argument is less than 1 and the second argument is positive
2.521 - * infinity,
2.522 - * </ul>
2.523 - * then the result is positive zero.
2.524 - *
2.525 - * <li>If the absolute value of the first argument equals 1 and the
2.526 - * second argument is infinite, then the result is NaN.
2.527 - *
2.528 - * <li>If
2.529 - * <ul>
2.530 - * <li>the first argument is positive zero and the second argument
2.531 - * is greater than zero, or
2.532 - * <li>the first argument is positive infinity and the second
2.533 - * argument is less than zero,
2.534 - * </ul>
2.535 - * then the result is positive zero.
2.536 - *
2.537 - * <li>If
2.538 - * <ul>
2.539 - * <li>the first argument is positive zero and the second argument
2.540 - * is less than zero, or
2.541 - * <li>the first argument is positive infinity and the second
2.542 - * argument is greater than zero,
2.543 - * </ul>
2.544 - * then the result is positive infinity.
2.545 - *
2.546 - * <li>If
2.547 - * <ul>
2.548 - * <li>the first argument is negative zero and the second argument
2.549 - * is greater than zero but not a finite odd integer, or
2.550 - * <li>the first argument is negative infinity and the second
2.551 - * argument is less than zero but not a finite odd integer,
2.552 - * </ul>
2.553 - * then the result is positive zero.
2.554 - *
2.555 - * <li>If
2.556 - * <ul>
2.557 - * <li>the first argument is negative zero and the second argument
2.558 - * is a positive finite odd integer, or
2.559 - * <li>the first argument is negative infinity and the second
2.560 - * argument is a negative finite odd integer,
2.561 - * </ul>
2.562 - * then the result is negative zero.
2.563 - *
2.564 - * <li>If
2.565 - * <ul>
2.566 - * <li>the first argument is negative zero and the second argument
2.567 - * is less than zero but not a finite odd integer, or
2.568 - * <li>the first argument is negative infinity and the second
2.569 - * argument is greater than zero but not a finite odd integer,
2.570 - * </ul>
2.571 - * then the result is positive infinity.
2.572 - *
2.573 - * <li>If
2.574 - * <ul>
2.575 - * <li>the first argument is negative zero and the second argument
2.576 - * is a negative finite odd integer, or
2.577 - * <li>the first argument is negative infinity and the second
2.578 - * argument is a positive finite odd integer,
2.579 - * </ul>
2.580 - * then the result is negative infinity.
2.581 - *
2.582 - * <li>If the first argument is finite and less than zero
2.583 - * <ul>
2.584 - * <li> if the second argument is a finite even integer, the
2.585 - * result is equal to the result of raising the absolute value of
2.586 - * the first argument to the power of the second argument
2.587 - *
2.588 - * <li>if the second argument is a finite odd integer, the result
2.589 - * is equal to the negative of the result of raising the absolute
2.590 - * value of the first argument to the power of the second
2.591 - * argument
2.592 - *
2.593 - * <li>if the second argument is finite and not an integer, then
2.594 - * the result is NaN.
2.595 - * </ul>
2.596 - *
2.597 - * <li>If both arguments are integers, then the result is exactly equal
2.598 - * to the mathematical result of raising the first argument to the power
2.599 - * of the second argument if that result can in fact be represented
2.600 - * exactly as a {@code double} value.</ul>
2.601 - *
2.602 - * <p>(In the foregoing descriptions, a floating-point value is
2.603 - * considered to be an integer if and only if it is finite and a
2.604 - * fixed point of the method {@link #ceil ceil} or,
2.605 - * equivalently, a fixed point of the method {@link #floor
2.606 - * floor}. A value is a fixed point of a one-argument
2.607 - * method if and only if the result of applying the method to the
2.608 - * value is equal to the value.)
2.609 - *
2.610 - * @param a base.
2.611 - * @param b the exponent.
2.612 - * @return the value {@code a}<sup>{@code b}</sup>.
2.613 - */
2.614 - public static native double pow(double a, double b);
2.615 -
2.616 - /**
2.617 - * Returns the closest {@code int} to the argument, with ties
2.618 - * rounding up.
2.619 - *
2.620 - * <p>Special cases:
2.621 - * <ul><li>If the argument is NaN, the result is 0.
2.622 - * <li>If the argument is negative infinity or any value less than or
2.623 - * equal to the value of {@code Integer.MIN_VALUE}, the result is
2.624 - * equal to the value of {@code Integer.MIN_VALUE}.
2.625 - * <li>If the argument is positive infinity or any value greater than or
2.626 - * equal to the value of {@code Integer.MAX_VALUE}, the result is
2.627 - * equal to the value of {@code Integer.MAX_VALUE}.</ul>
2.628 - *
2.629 - * @param a a floating-point value to be rounded to an integer.
2.630 - * @return the value of the argument rounded to the nearest
2.631 - * {@code int} value.
2.632 - * @see java.lang.Integer#MAX_VALUE
2.633 - * @see java.lang.Integer#MIN_VALUE
2.634 - */
2.635 - public static int round(float a) {
2.636 - return Math.round(a);
2.637 - }
2.638 -
2.639 - /**
2.640 - * Returns the closest {@code long} to the argument, with ties
2.641 - * rounding up.
2.642 - *
2.643 - * <p>Special cases:
2.644 - * <ul><li>If the argument is NaN, the result is 0.
2.645 - * <li>If the argument is negative infinity or any value less than or
2.646 - * equal to the value of {@code Long.MIN_VALUE}, the result is
2.647 - * equal to the value of {@code Long.MIN_VALUE}.
2.648 - * <li>If the argument is positive infinity or any value greater than or
2.649 - * equal to the value of {@code Long.MAX_VALUE}, the result is
2.650 - * equal to the value of {@code Long.MAX_VALUE}.</ul>
2.651 - *
2.652 - * @param a a floating-point value to be rounded to a
2.653 - * {@code long}.
2.654 - * @return the value of the argument rounded to the nearest
2.655 - * {@code long} value.
2.656 - * @see java.lang.Long#MAX_VALUE
2.657 - * @see java.lang.Long#MIN_VALUE
2.658 - */
2.659 - public static long round(double a) {
2.660 - return Math.round(a);
2.661 - }
2.662 -
2.663 - /**
2.664 - * Returns a {@code double} value with a positive sign, greater
2.665 - * than or equal to {@code 0.0} and less than {@code 1.0}.
2.666 - * Returned values are chosen pseudorandomly with (approximately)
2.667 - * uniform distribution from that range.
2.668 - *
2.669 - * <p>When this method is first called, it creates a single new
2.670 - * pseudorandom-number generator, exactly as if by the expression
2.671 - *
2.672 - * <blockquote>{@code new java.util.Random()}</blockquote>
2.673 - *
2.674 - * This new pseudorandom-number generator is used thereafter for
2.675 - * all calls to this method and is used nowhere else.
2.676 - *
2.677 - * <p>This method is properly synchronized to allow correct use by
2.678 - * more than one thread. However, if many threads need to generate
2.679 - * pseudorandom numbers at a great rate, it may reduce contention
2.680 - * for each thread to have its own pseudorandom number generator.
2.681 - *
2.682 - * @return a pseudorandom {@code double} greater than or equal
2.683 - * to {@code 0.0} and less than {@code 1.0}.
2.684 - * @see Random#nextDouble()
2.685 - */
2.686 - public static double random() {
2.687 - throw new UnsupportedOperationException();
2.688 - }
2.689 -
2.690 - /**
2.691 - * Returns the absolute value of an {@code int} value..
2.692 - * If the argument is not negative, the argument is returned.
2.693 - * If the argument is negative, the negation of the argument is returned.
2.694 - *
2.695 - * <p>Note that if the argument is equal to the value of
2.696 - * {@link Integer#MIN_VALUE}, the most negative representable
2.697 - * {@code int} value, the result is that same value, which is
2.698 - * negative.
2.699 - *
2.700 - * @param a the argument whose absolute value is to be determined.
2.701 - * @return the absolute value of the argument.
2.702 - */
2.703 - public static int abs(int a) {
2.704 - return (a < 0) ? -a : a;
2.705 - }
2.706 -
2.707 - /**
2.708 - * Returns the absolute value of a {@code long} value.
2.709 - * If the argument is not negative, the argument is returned.
2.710 - * If the argument is negative, the negation of the argument is returned.
2.711 - *
2.712 - * <p>Note that if the argument is equal to the value of
2.713 - * {@link Long#MIN_VALUE}, the most negative representable
2.714 - * {@code long} value, the result is that same value, which
2.715 - * is negative.
2.716 - *
2.717 - * @param a the argument whose absolute value is to be determined.
2.718 - * @return the absolute value of the argument.
2.719 - */
2.720 - public static long abs(long a) {
2.721 - return (a < 0) ? -a : a;
2.722 - }
2.723 -
2.724 - /**
2.725 - * Returns the absolute value of a {@code float} value.
2.726 - * If the argument is not negative, the argument is returned.
2.727 - * If the argument is negative, the negation of the argument is returned.
2.728 - * Special cases:
2.729 - * <ul><li>If the argument is positive zero or negative zero, the
2.730 - * result is positive zero.
2.731 - * <li>If the argument is infinite, the result is positive infinity.
2.732 - * <li>If the argument is NaN, the result is NaN.</ul>
2.733 - * In other words, the result is the same as the value of the expression:
2.734 - * <p>{@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
2.735 - *
2.736 - * @param a the argument whose absolute value is to be determined
2.737 - * @return the absolute value of the argument.
2.738 - */
2.739 - public static float abs(float a) {
2.740 - return (a <= 0.0F) ? 0.0F - a : a;
2.741 - }
2.742 -
2.743 - /**
2.744 - * Returns the absolute value of a {@code double} value.
2.745 - * If the argument is not negative, the argument is returned.
2.746 - * If the argument is negative, the negation of the argument is returned.
2.747 - * Special cases:
2.748 - * <ul><li>If the argument is positive zero or negative zero, the result
2.749 - * is positive zero.
2.750 - * <li>If the argument is infinite, the result is positive infinity.
2.751 - * <li>If the argument is NaN, the result is NaN.</ul>
2.752 - * In other words, the result is the same as the value of the expression:
2.753 - * <p>{@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
2.754 - *
2.755 - * @param a the argument whose absolute value is to be determined
2.756 - * @return the absolute value of the argument.
2.757 - */
2.758 - public static double abs(double a) {
2.759 - return (a <= 0.0D) ? 0.0D - a : a;
2.760 - }
2.761 -
2.762 - /**
2.763 - * Returns the greater of two {@code int} values. That is, the
2.764 - * result is the argument closer to the value of
2.765 - * {@link Integer#MAX_VALUE}. If the arguments have the same value,
2.766 - * the result is that same value.
2.767 - *
2.768 - * @param a an argument.
2.769 - * @param b another argument.
2.770 - * @return the larger of {@code a} and {@code b}.
2.771 - */
2.772 - public static int max(int a, int b) {
2.773 - return (a >= b) ? a : b;
2.774 - }
2.775 -
2.776 - /**
2.777 - * Returns the greater of two {@code long} values. That is, the
2.778 - * result is the argument closer to the value of
2.779 - * {@link Long#MAX_VALUE}. If the arguments have the same value,
2.780 - * the result is that same value.
2.781 - *
2.782 - * @param a an argument.
2.783 - * @param b another argument.
2.784 - * @return the larger of {@code a} and {@code b}.
2.785 - */
2.786 - public static long max(long a, long b) {
2.787 - return (a >= b) ? a : b;
2.788 - }
2.789 -
2.790 - // Use raw bit-wise conversions on guaranteed non-NaN arguments.
2.791 - private static long negativeZeroFloatBits = Float.floatToRawIntBits(-0.0f);
2.792 - private static long negativeZeroDoubleBits = Double.doubleToRawLongBits(-0.0d);
2.793 -
2.794 - /**
2.795 - * Returns the greater of two {@code float} values. That is,
2.796 - * the result is the argument closer to positive infinity. If the
2.797 - * arguments have the same value, the result is that same
2.798 - * value. If either value is NaN, then the result is NaN. Unlike
2.799 - * the numerical comparison operators, this method considers
2.800 - * negative zero to be strictly smaller than positive zero. If one
2.801 - * argument is positive zero and the other negative zero, the
2.802 - * result is positive zero.
2.803 - *
2.804 - * @param a an argument.
2.805 - * @param b another argument.
2.806 - * @return the larger of {@code a} and {@code b}.
2.807 - */
2.808 - public static float max(float a, float b) {
2.809 - if (a != a)
2.810 - return a; // a is NaN
2.811 - if ((a == 0.0f) &&
2.812 - (b == 0.0f) &&
2.813 - (Float.floatToRawIntBits(a) == negativeZeroFloatBits)) {
2.814 - // Raw conversion ok since NaN can't map to -0.0.
2.815 - return b;
2.816 - }
2.817 - return (a >= b) ? a : b;
2.818 - }
2.819 -
2.820 - /**
2.821 - * Returns the greater of two {@code double} values. That
2.822 - * is, the result is the argument closer to positive infinity. If
2.823 - * the arguments have the same value, the result is that same
2.824 - * value. If either value is NaN, then the result is NaN. Unlike
2.825 - * the numerical comparison operators, this method considers
2.826 - * negative zero to be strictly smaller than positive zero. If one
2.827 - * argument is positive zero and the other negative zero, the
2.828 - * result is positive zero.
2.829 - *
2.830 - * @param a an argument.
2.831 - * @param b another argument.
2.832 - * @return the larger of {@code a} and {@code b}.
2.833 - */
2.834 - public static double max(double a, double b) {
2.835 - if (a != a)
2.836 - return a; // a is NaN
2.837 - if ((a == 0.0d) &&
2.838 - (b == 0.0d) &&
2.839 - (Double.doubleToRawLongBits(a) == negativeZeroDoubleBits)) {
2.840 - // Raw conversion ok since NaN can't map to -0.0.
2.841 - return b;
2.842 - }
2.843 - return (a >= b) ? a : b;
2.844 - }
2.845 -
2.846 - /**
2.847 - * Returns the smaller of two {@code int} values. That is,
2.848 - * the result the argument closer to the value of
2.849 - * {@link Integer#MIN_VALUE}. If the arguments have the same
2.850 - * value, the result is that same value.
2.851 - *
2.852 - * @param a an argument.
2.853 - * @param b another argument.
2.854 - * @return the smaller of {@code a} and {@code b}.
2.855 - */
2.856 - public static int min(int a, int b) {
2.857 - return (a <= b) ? a : b;
2.858 - }
2.859 -
2.860 - /**
2.861 - * Returns the smaller of two {@code long} values. That is,
2.862 - * the result is the argument closer to the value of
2.863 - * {@link Long#MIN_VALUE}. If the arguments have the same
2.864 - * value, the result is that same value.
2.865 - *
2.866 - * @param a an argument.
2.867 - * @param b another argument.
2.868 - * @return the smaller of {@code a} and {@code b}.
2.869 - */
2.870 - public static long min(long a, long b) {
2.871 - return (a <= b) ? a : b;
2.872 - }
2.873 -
2.874 - /**
2.875 - * Returns the smaller of two {@code float} values. That is,
2.876 - * the result is the value closer to negative infinity. If the
2.877 - * arguments have the same value, the result is that same
2.878 - * value. If either value is NaN, then the result is NaN. Unlike
2.879 - * the numerical comparison operators, this method considers
2.880 - * negative zero to be strictly smaller than positive zero. If
2.881 - * one argument is positive zero and the other is negative zero,
2.882 - * the result is negative zero.
2.883 - *
2.884 - * @param a an argument.
2.885 - * @param b another argument.
2.886 - * @return the smaller of {@code a} and {@code b.}
2.887 - */
2.888 - public static float min(float a, float b) {
2.889 - if (a != a)
2.890 - return a; // a is NaN
2.891 - if ((a == 0.0f) &&
2.892 - (b == 0.0f) &&
2.893 - (Float.floatToRawIntBits(b) == negativeZeroFloatBits)) {
2.894 - // Raw conversion ok since NaN can't map to -0.0.
2.895 - return b;
2.896 - }
2.897 - return (a <= b) ? a : b;
2.898 - }
2.899 -
2.900 - /**
2.901 - * Returns the smaller of two {@code double} values. That
2.902 - * is, the result is the value closer to negative infinity. If the
2.903 - * arguments have the same value, the result is that same
2.904 - * value. If either value is NaN, then the result is NaN. Unlike
2.905 - * the numerical comparison operators, this method considers
2.906 - * negative zero to be strictly smaller than positive zero. If one
2.907 - * argument is positive zero and the other is negative zero, the
2.908 - * result is negative zero.
2.909 - *
2.910 - * @param a an argument.
2.911 - * @param b another argument.
2.912 - * @return the smaller of {@code a} and {@code b}.
2.913 - */
2.914 - public static double min(double a, double b) {
2.915 - if (a != a)
2.916 - return a; // a is NaN
2.917 - if ((a == 0.0d) &&
2.918 - (b == 0.0d) &&
2.919 - (Double.doubleToRawLongBits(b) == negativeZeroDoubleBits)) {
2.920 - // Raw conversion ok since NaN can't map to -0.0.
2.921 - return b;
2.922 - }
2.923 - return (a <= b) ? a : b;
2.924 - }
2.925 -
2.926 - /**
2.927 - * Returns the size of an ulp of the argument. An ulp of a
2.928 - * {@code double} value is the positive distance between this
2.929 - * floating-point value and the {@code double} value next
2.930 - * larger in magnitude. Note that for non-NaN <i>x</i>,
2.931 - * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
2.932 - *
2.933 - * <p>Special Cases:
2.934 - * <ul>
2.935 - * <li> If the argument is NaN, then the result is NaN.
2.936 - * <li> If the argument is positive or negative infinity, then the
2.937 - * result is positive infinity.
2.938 - * <li> If the argument is positive or negative zero, then the result is
2.939 - * {@code Double.MIN_VALUE}.
2.940 - * <li> If the argument is ±{@code Double.MAX_VALUE}, then
2.941 - * the result is equal to 2<sup>971</sup>.
2.942 - * </ul>
2.943 - *
2.944 - * @param d the floating-point value whose ulp is to be returned
2.945 - * @return the size of an ulp of the argument
2.946 - * @author Joseph D. Darcy
2.947 - * @since 1.5
2.948 - */
2.949 - public static double ulp(double d) {
2.950 - throw new UnsupportedOperationException();
2.951 - }
2.952 -
2.953 - /**
2.954 - * Returns the size of an ulp of the argument. An ulp of a
2.955 - * {@code float} value is the positive distance between this
2.956 - * floating-point value and the {@code float} value next
2.957 - * larger in magnitude. Note that for non-NaN <i>x</i>,
2.958 - * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
2.959 - *
2.960 - * <p>Special Cases:
2.961 - * <ul>
2.962 - * <li> If the argument is NaN, then the result is NaN.
2.963 - * <li> If the argument is positive or negative infinity, then the
2.964 - * result is positive infinity.
2.965 - * <li> If the argument is positive or negative zero, then the result is
2.966 - * {@code Float.MIN_VALUE}.
2.967 - * <li> If the argument is ±{@code Float.MAX_VALUE}, then
2.968 - * the result is equal to 2<sup>104</sup>.
2.969 - * </ul>
2.970 - *
2.971 - * @param f the floating-point value whose ulp is to be returned
2.972 - * @return the size of an ulp of the argument
2.973 - * @author Joseph D. Darcy
2.974 - * @since 1.5
2.975 - */
2.976 - public static float ulp(float f) {
2.977 - throw new UnsupportedOperationException();
2.978 - }
2.979 -
2.980 - /**
2.981 - * Returns the signum function of the argument; zero if the argument
2.982 - * is zero, 1.0 if the argument is greater than zero, -1.0 if the
2.983 - * argument is less than zero.
2.984 - *
2.985 - * <p>Special Cases:
2.986 - * <ul>
2.987 - * <li> If the argument is NaN, then the result is NaN.
2.988 - * <li> If the argument is positive zero or negative zero, then the
2.989 - * result is the same as the argument.
2.990 - * </ul>
2.991 - *
2.992 - * @param d the floating-point value whose signum is to be returned
2.993 - * @return the signum function of the argument
2.994 - * @author Joseph D. Darcy
2.995 - * @since 1.5
2.996 - */
2.997 - public static double signum(double d) {
2.998 - throw new UnsupportedOperationException();
2.999 - }
2.1000 -
2.1001 - /**
2.1002 - * Returns the signum function of the argument; zero if the argument
2.1003 - * is zero, 1.0f if the argument is greater than zero, -1.0f if the
2.1004 - * argument is less than zero.
2.1005 - *
2.1006 - * <p>Special Cases:
2.1007 - * <ul>
2.1008 - * <li> If the argument is NaN, then the result is NaN.
2.1009 - * <li> If the argument is positive zero or negative zero, then the
2.1010 - * result is the same as the argument.
2.1011 - * </ul>
2.1012 - *
2.1013 - * @param f the floating-point value whose signum is to be returned
2.1014 - * @return the signum function of the argument
2.1015 - * @author Joseph D. Darcy
2.1016 - * @since 1.5
2.1017 - */
2.1018 - public static float signum(float f) {
2.1019 - throw new UnsupportedOperationException();
2.1020 - }
2.1021 -
2.1022 - /**
2.1023 - * Returns the hyperbolic sine of a {@code double} value.
2.1024 - * The hyperbolic sine of <i>x</i> is defined to be
2.1025 - * (<i>e<sup>x</sup> - e<sup>-x</sup></i>)/2
2.1026 - * where <i>e</i> is {@linkplain Math#E Euler's number}.
2.1027 - *
2.1028 - * <p>Special cases:
2.1029 - * <ul>
2.1030 - *
2.1031 - * <li>If the argument is NaN, then the result is NaN.
2.1032 - *
2.1033 - * <li>If the argument is infinite, then the result is an infinity
2.1034 - * with the same sign as the argument.
2.1035 - *
2.1036 - * <li>If the argument is zero, then the result is a zero with the
2.1037 - * same sign as the argument.
2.1038 - *
2.1039 - * </ul>
2.1040 - *
2.1041 - * @param x The number whose hyperbolic sine is to be returned.
2.1042 - * @return The hyperbolic sine of {@code x}.
2.1043 - * @since 1.5
2.1044 - */
2.1045 - public static native double sinh(double x);
2.1046 -
2.1047 - /**
2.1048 - * Returns the hyperbolic cosine of a {@code double} value.
2.1049 - * The hyperbolic cosine of <i>x</i> is defined to be
2.1050 - * (<i>e<sup>x</sup> + e<sup>-x</sup></i>)/2
2.1051 - * where <i>e</i> is {@linkplain Math#E Euler's number}.
2.1052 - *
2.1053 - * <p>Special cases:
2.1054 - * <ul>
2.1055 - *
2.1056 - * <li>If the argument is NaN, then the result is NaN.
2.1057 - *
2.1058 - * <li>If the argument is infinite, then the result is positive
2.1059 - * infinity.
2.1060 - *
2.1061 - * <li>If the argument is zero, then the result is {@code 1.0}.
2.1062 - *
2.1063 - * </ul>
2.1064 - *
2.1065 - * @param x The number whose hyperbolic cosine is to be returned.
2.1066 - * @return The hyperbolic cosine of {@code x}.
2.1067 - * @since 1.5
2.1068 - */
2.1069 - public static native double cosh(double x);
2.1070 -
2.1071 - /**
2.1072 - * Returns the hyperbolic tangent of a {@code double} value.
2.1073 - * The hyperbolic tangent of <i>x</i> is defined to be
2.1074 - * (<i>e<sup>x</sup> - e<sup>-x</sup></i>)/(<i>e<sup>x</sup> + e<sup>-x</sup></i>),
2.1075 - * in other words, {@linkplain Math#sinh
2.1076 - * sinh(<i>x</i>)}/{@linkplain Math#cosh cosh(<i>x</i>)}. Note
2.1077 - * that the absolute value of the exact tanh is always less than
2.1078 - * 1.
2.1079 - *
2.1080 - * <p>Special cases:
2.1081 - * <ul>
2.1082 - *
2.1083 - * <li>If the argument is NaN, then the result is NaN.
2.1084 - *
2.1085 - * <li>If the argument is zero, then the result is a zero with the
2.1086 - * same sign as the argument.
2.1087 - *
2.1088 - * <li>If the argument is positive infinity, then the result is
2.1089 - * {@code +1.0}.
2.1090 - *
2.1091 - * <li>If the argument is negative infinity, then the result is
2.1092 - * {@code -1.0}.
2.1093 - *
2.1094 - * </ul>
2.1095 - *
2.1096 - * @param x The number whose hyperbolic tangent is to be returned.
2.1097 - * @return The hyperbolic tangent of {@code x}.
2.1098 - * @since 1.5
2.1099 - */
2.1100 - public static native double tanh(double x);
2.1101 -
2.1102 - /**
2.1103 - * Returns sqrt(<i>x</i><sup>2</sup> +<i>y</i><sup>2</sup>)
2.1104 - * without intermediate overflow or underflow.
2.1105 - *
2.1106 - * <p>Special cases:
2.1107 - * <ul>
2.1108 - *
2.1109 - * <li> If either argument is infinite, then the result
2.1110 - * is positive infinity.
2.1111 - *
2.1112 - * <li> If either argument is NaN and neither argument is infinite,
2.1113 - * then the result is NaN.
2.1114 - *
2.1115 - * </ul>
2.1116 - *
2.1117 - * @param x a value
2.1118 - * @param y a value
2.1119 - * @return sqrt(<i>x</i><sup>2</sup> +<i>y</i><sup>2</sup>)
2.1120 - * without intermediate overflow or underflow
2.1121 - * @since 1.5
2.1122 - */
2.1123 - public static native double hypot(double x, double y);
2.1124 -
2.1125 - /**
2.1126 - * Returns <i>e</i><sup>x</sup> -1. Note that for values of
2.1127 - * <i>x</i> near 0, the exact sum of
2.1128 - * {@code expm1(x)} + 1 is much closer to the true
2.1129 - * result of <i>e</i><sup>x</sup> than {@code exp(x)}.
2.1130 - *
2.1131 - * <p>Special cases:
2.1132 - * <ul>
2.1133 - * <li>If the argument is NaN, the result is NaN.
2.1134 - *
2.1135 - * <li>If the argument is positive infinity, then the result is
2.1136 - * positive infinity.
2.1137 - *
2.1138 - * <li>If the argument is negative infinity, then the result is
2.1139 - * -1.0.
2.1140 - *
2.1141 - * <li>If the argument is zero, then the result is a zero with the
2.1142 - * same sign as the argument.
2.1143 - *
2.1144 - * </ul>
2.1145 - *
2.1146 - * @param x the exponent to raise <i>e</i> to in the computation of
2.1147 - * <i>e</i><sup>{@code x}</sup> -1.
2.1148 - * @return the value <i>e</i><sup>{@code x}</sup> - 1.
2.1149 - * @since 1.5
2.1150 - */
2.1151 - public static native double expm1(double x);
2.1152 -
2.1153 - /**
2.1154 - * Returns the natural logarithm of the sum of the argument and 1.
2.1155 - * Note that for small values {@code x}, the result of
2.1156 - * {@code log1p(x)} is much closer to the true result of ln(1
2.1157 - * + {@code x}) than the floating-point evaluation of
2.1158 - * {@code log(1.0+x)}.
2.1159 - *
2.1160 - * <p>Special cases:
2.1161 - * <ul>
2.1162 - *
2.1163 - * <li>If the argument is NaN or less than -1, then the result is
2.1164 - * NaN.
2.1165 - *
2.1166 - * <li>If the argument is positive infinity, then the result is
2.1167 - * positive infinity.
2.1168 - *
2.1169 - * <li>If the argument is negative one, then the result is
2.1170 - * negative infinity.
2.1171 - *
2.1172 - * <li>If the argument is zero, then the result is a zero with the
2.1173 - * same sign as the argument.
2.1174 - *
2.1175 - * </ul>
2.1176 - *
2.1177 - * @param x a value
2.1178 - * @return the value ln({@code x} + 1), the natural
2.1179 - * log of {@code x} + 1
2.1180 - * @since 1.5
2.1181 - */
2.1182 - public static native double log1p(double x);
2.1183 -
2.1184 - /**
2.1185 - * Returns the first floating-point argument with the sign of the
2.1186 - * second floating-point argument. For this method, a NaN
2.1187 - * {@code sign} argument is always treated as if it were
2.1188 - * positive.
2.1189 - *
2.1190 - * @param magnitude the parameter providing the magnitude of the result
2.1191 - * @param sign the parameter providing the sign of the result
2.1192 - * @return a value with the magnitude of {@code magnitude}
2.1193 - * and the sign of {@code sign}.
2.1194 - * @since 1.6
2.1195 - */
2.1196 - public static double copySign(double magnitude, double sign) {
2.1197 - throw new UnsupportedOperationException();
2.1198 - }
2.1199 -
2.1200 - /**
2.1201 - * Returns the first floating-point argument with the sign of the
2.1202 - * second floating-point argument. For this method, a NaN
2.1203 - * {@code sign} argument is always treated as if it were
2.1204 - * positive.
2.1205 - *
2.1206 - * @param magnitude the parameter providing the magnitude of the result
2.1207 - * @param sign the parameter providing the sign of the result
2.1208 - * @return a value with the magnitude of {@code magnitude}
2.1209 - * and the sign of {@code sign}.
2.1210 - * @since 1.6
2.1211 - */
2.1212 - public static float copySign(float magnitude, float sign) {
2.1213 - throw new UnsupportedOperationException();
2.1214 - }
2.1215 - /**
2.1216 - * Returns the unbiased exponent used in the representation of a
2.1217 - * {@code float}. Special cases:
2.1218 - *
2.1219 - * <ul>
2.1220 - * <li>If the argument is NaN or infinite, then the result is
2.1221 - * {@link Float#MAX_EXPONENT} + 1.
2.1222 - * <li>If the argument is zero or subnormal, then the result is
2.1223 - * {@link Float#MIN_EXPONENT} -1.
2.1224 - * </ul>
2.1225 - * @param f a {@code float} value
2.1226 - * @since 1.6
2.1227 - */
2.1228 - public static int getExponent(float f) {
2.1229 - throw new UnsupportedOperationException();
2.1230 - }
2.1231 -
2.1232 - /**
2.1233 - * Returns the unbiased exponent used in the representation of a
2.1234 - * {@code double}. Special cases:
2.1235 - *
2.1236 - * <ul>
2.1237 - * <li>If the argument is NaN or infinite, then the result is
2.1238 - * {@link Double#MAX_EXPONENT} + 1.
2.1239 - * <li>If the argument is zero or subnormal, then the result is
2.1240 - * {@link Double#MIN_EXPONENT} -1.
2.1241 - * </ul>
2.1242 - * @param d a {@code double} value
2.1243 - * @since 1.6
2.1244 - */
2.1245 - public static int getExponent(double d) {
2.1246 - throw new UnsupportedOperationException();
2.1247 - }
2.1248 -
2.1249 - /**
2.1250 - * Returns the floating-point number adjacent to the first
2.1251 - * argument in the direction of the second argument. If both
2.1252 - * arguments compare as equal the second argument is returned.
2.1253 - *
2.1254 - * <p>Special cases:
2.1255 - * <ul>
2.1256 - * <li> If either argument is a NaN, then NaN is returned.
2.1257 - *
2.1258 - * <li> If both arguments are signed zeros, {@code direction}
2.1259 - * is returned unchanged (as implied by the requirement of
2.1260 - * returning the second argument if the arguments compare as
2.1261 - * equal).
2.1262 - *
2.1263 - * <li> If {@code start} is
2.1264 - * ±{@link Double#MIN_VALUE} and {@code direction}
2.1265 - * has a value such that the result should have a smaller
2.1266 - * magnitude, then a zero with the same sign as {@code start}
2.1267 - * is returned.
2.1268 - *
2.1269 - * <li> If {@code start} is infinite and
2.1270 - * {@code direction} has a value such that the result should
2.1271 - * have a smaller magnitude, {@link Double#MAX_VALUE} with the
2.1272 - * same sign as {@code start} is returned.
2.1273 - *
2.1274 - * <li> If {@code start} is equal to ±
2.1275 - * {@link Double#MAX_VALUE} and {@code direction} has a
2.1276 - * value such that the result should have a larger magnitude, an
2.1277 - * infinity with same sign as {@code start} is returned.
2.1278 - * </ul>
2.1279 - *
2.1280 - * @param start starting floating-point value
2.1281 - * @param direction value indicating which of
2.1282 - * {@code start}'s neighbors or {@code start} should
2.1283 - * be returned
2.1284 - * @return The floating-point number adjacent to {@code start} in the
2.1285 - * direction of {@code direction}.
2.1286 - * @since 1.6
2.1287 - */
2.1288 - public static double nextAfter(double start, double direction) {
2.1289 - throw new UnsupportedOperationException();
2.1290 - }
2.1291 -
2.1292 - /**
2.1293 - * Returns the floating-point number adjacent to the first
2.1294 - * argument in the direction of the second argument. If both
2.1295 - * arguments compare as equal a value equivalent to the second argument
2.1296 - * is returned.
2.1297 - *
2.1298 - * <p>Special cases:
2.1299 - * <ul>
2.1300 - * <li> If either argument is a NaN, then NaN is returned.
2.1301 - *
2.1302 - * <li> If both arguments are signed zeros, a value equivalent
2.1303 - * to {@code direction} is returned.
2.1304 - *
2.1305 - * <li> If {@code start} is
2.1306 - * ±{@link Float#MIN_VALUE} and {@code direction}
2.1307 - * has a value such that the result should have a smaller
2.1308 - * magnitude, then a zero with the same sign as {@code start}
2.1309 - * is returned.
2.1310 - *
2.1311 - * <li> If {@code start} is infinite and
2.1312 - * {@code direction} has a value such that the result should
2.1313 - * have a smaller magnitude, {@link Float#MAX_VALUE} with the
2.1314 - * same sign as {@code start} is returned.
2.1315 - *
2.1316 - * <li> If {@code start} is equal to ±
2.1317 - * {@link Float#MAX_VALUE} and {@code direction} has a
2.1318 - * value such that the result should have a larger magnitude, an
2.1319 - * infinity with same sign as {@code start} is returned.
2.1320 - * </ul>
2.1321 - *
2.1322 - * @param start starting floating-point value
2.1323 - * @param direction value indicating which of
2.1324 - * {@code start}'s neighbors or {@code start} should
2.1325 - * be returned
2.1326 - * @return The floating-point number adjacent to {@code start} in the
2.1327 - * direction of {@code direction}.
2.1328 - * @since 1.6
2.1329 - */
2.1330 - public static float nextAfter(float start, double direction) {
2.1331 - throw new UnsupportedOperationException();
2.1332 - }
2.1333 -
2.1334 - /**
2.1335 - * Returns the floating-point value adjacent to {@code d} in
2.1336 - * the direction of positive infinity. This method is
2.1337 - * semantically equivalent to {@code nextAfter(d,
2.1338 - * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
2.1339 - * implementation may run faster than its equivalent
2.1340 - * {@code nextAfter} call.
2.1341 - *
2.1342 - * <p>Special Cases:
2.1343 - * <ul>
2.1344 - * <li> If the argument is NaN, the result is NaN.
2.1345 - *
2.1346 - * <li> If the argument is positive infinity, the result is
2.1347 - * positive infinity.
2.1348 - *
2.1349 - * <li> If the argument is zero, the result is
2.1350 - * {@link Double#MIN_VALUE}
2.1351 - *
2.1352 - * </ul>
2.1353 - *
2.1354 - * @param d starting floating-point value
2.1355 - * @return The adjacent floating-point value closer to positive
2.1356 - * infinity.
2.1357 - * @since 1.6
2.1358 - */
2.1359 - public static double nextUp(double d) {
2.1360 - throw new UnsupportedOperationException();
2.1361 - }
2.1362 -
2.1363 - /**
2.1364 - * Returns the floating-point value adjacent to {@code f} in
2.1365 - * the direction of positive infinity. This method is
2.1366 - * semantically equivalent to {@code nextAfter(f,
2.1367 - * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
2.1368 - * implementation may run faster than its equivalent
2.1369 - * {@code nextAfter} call.
2.1370 - *
2.1371 - * <p>Special Cases:
2.1372 - * <ul>
2.1373 - * <li> If the argument is NaN, the result is NaN.
2.1374 - *
2.1375 - * <li> If the argument is positive infinity, the result is
2.1376 - * positive infinity.
2.1377 - *
2.1378 - * <li> If the argument is zero, the result is
2.1379 - * {@link Float#MIN_VALUE}
2.1380 - *
2.1381 - * </ul>
2.1382 - *
2.1383 - * @param f starting floating-point value
2.1384 - * @return The adjacent floating-point value closer to positive
2.1385 - * infinity.
2.1386 - * @since 1.6
2.1387 - */
2.1388 - public static float nextUp(float f) {
2.1389 - throw new UnsupportedOperationException();
2.1390 - }
2.1391 -
2.1392 -
2.1393 - /**
2.1394 - * Return {@code d} ×
2.1395 - * 2<sup>{@code scaleFactor}</sup> rounded as if performed
2.1396 - * by a single correctly rounded floating-point multiply to a
2.1397 - * member of the double value set. See the Java
2.1398 - * Language Specification for a discussion of floating-point
2.1399 - * value sets. If the exponent of the result is between {@link
2.1400 - * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
2.1401 - * answer is calculated exactly. If the exponent of the result
2.1402 - * would be larger than {@code Double.MAX_EXPONENT}, an
2.1403 - * infinity is returned. Note that if the result is subnormal,
2.1404 - * precision may be lost; that is, when {@code scalb(x, n)}
2.1405 - * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
2.1406 - * <i>x</i>. When the result is non-NaN, the result has the same
2.1407 - * sign as {@code d}.
2.1408 - *
2.1409 - * <p>Special cases:
2.1410 - * <ul>
2.1411 - * <li> If the first argument is NaN, NaN is returned.
2.1412 - * <li> If the first argument is infinite, then an infinity of the
2.1413 - * same sign is returned.
2.1414 - * <li> If the first argument is zero, then a zero of the same
2.1415 - * sign is returned.
2.1416 - * </ul>
2.1417 - *
2.1418 - * @param d number to be scaled by a power of two.
2.1419 - * @param scaleFactor power of 2 used to scale {@code d}
2.1420 - * @return {@code d} × 2<sup>{@code scaleFactor}</sup>
2.1421 - * @since 1.6
2.1422 - */
2.1423 - public static double scalb(double d, int scaleFactor) {
2.1424 - throw new UnsupportedOperationException();
2.1425 - }
2.1426 -
2.1427 - /**
2.1428 - * Return {@code f} ×
2.1429 - * 2<sup>{@code scaleFactor}</sup> rounded as if performed
2.1430 - * by a single correctly rounded floating-point multiply to a
2.1431 - * member of the float value set. See the Java
2.1432 - * Language Specification for a discussion of floating-point
2.1433 - * value sets. If the exponent of the result is between {@link
2.1434 - * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
2.1435 - * answer is calculated exactly. If the exponent of the result
2.1436 - * would be larger than {@code Float.MAX_EXPONENT}, an
2.1437 - * infinity is returned. Note that if the result is subnormal,
2.1438 - * precision may be lost; that is, when {@code scalb(x, n)}
2.1439 - * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
2.1440 - * <i>x</i>. When the result is non-NaN, the result has the same
2.1441 - * sign as {@code f}.
2.1442 - *
2.1443 - * <p>Special cases:
2.1444 - * <ul>
2.1445 - * <li> If the first argument is NaN, NaN is returned.
2.1446 - * <li> If the first argument is infinite, then an infinity of the
2.1447 - * same sign is returned.
2.1448 - * <li> If the first argument is zero, then a zero of the same
2.1449 - * sign is returned.
2.1450 - * </ul>
2.1451 - *
2.1452 - * @param f number to be scaled by a power of two.
2.1453 - * @param scaleFactor power of 2 used to scale {@code f}
2.1454 - * @return {@code f} × 2<sup>{@code scaleFactor}</sup>
2.1455 - * @since 1.6
2.1456 - */
2.1457 - public static float scalb(float f, int scaleFactor) {
2.1458 - throw new UnsupportedOperationException();
2.1459 - }
2.1460 -}
3.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Tue Oct 30 22:59:31 2012 +0100
3.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Tue Oct 30 23:33:29 2012 +0100
3.3 @@ -19,8 +19,8 @@
3.4
3.5 import javax.script.Invocable;
3.6 import javax.script.ScriptException;
3.7 +import static org.testng.Assert.*;
3.8 import org.testng.annotations.BeforeClass;
3.9 -import static org.testng.Assert.*;
3.10 import org.testng.annotations.Test;
3.11
3.12 /**
3.13 @@ -45,6 +45,16 @@
3.14 "3.3"
3.15 );
3.16 }
3.17 +
3.18 + @Test public void javalog1000() throws Exception {
3.19 + assertEquals(3.0, Math.log10(1000.0), 0.00003, "log_10(1000) == 3");
3.20 + }
3.21 +
3.22 + @Test public void jslog1000() throws Exception {
3.23 + assertExec("log_10(1000) == 3", "java_lang_Math_log10DD",
3.24 + Double.valueOf(3.0), 1000.0
3.25 + );
3.26 + }
3.27
3.28
3.29 private static CharSequence codeSeq;
3.30 @@ -76,6 +86,12 @@
3.31 if (expRes.equals(ret)) {
3.32 return;
3.33 }
3.34 + if (expRes instanceof Double && ret instanceof Double) {
3.35 + double expD = ((Double)expRes).doubleValue();
3.36 + double retD = ((Double)ret).doubleValue();
3.37 + assertEquals(retD, expD, 0.000004, msg + " was " + ret + "\n" + codeSeq);
3.38 + return;
3.39 + }
3.40 assertEquals(ret, expRes, msg + "was: " + ret + "\n" + codeSeq);
3.41 }
3.42