1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/rt/emul/mini/src/main/java/java/lang/Math.java Tue Feb 26 16:54:16 2013 +0100
1.3 @@ -0,0 +1,1311 @@
1.4 +/*
1.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1.7 + *
1.8 + * This code is free software; you can redistribute it and/or modify it
1.9 + * under the terms of the GNU General Public License version 2 only, as
1.10 + * published by the Free Software Foundation. Oracle designates this
1.11 + * particular file as subject to the "Classpath" exception as provided
1.12 + * by Oracle in the LICENSE file that accompanied this code.
1.13 + *
1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1.17 + * version 2 for more details (a copy is included in the LICENSE file that
1.18 + * accompanied this code).
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License version
1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1.23 + *
1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1.25 + * or visit www.oracle.com if you need additional information or have any
1.26 + * questions.
1.27 + */
1.28 +
1.29 +package java.lang;
1.30 +
1.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
1.32 +
1.33 +
1.34 +/**
1.35 + * The class {@code Math} contains methods for performing basic
1.36 + * numeric operations such as the elementary exponential, logarithm,
1.37 + * square root, and trigonometric functions.
1.38 + *
1.39 + * <p>Unlike some of the numeric methods of class
1.40 + * {@code StrictMath}, all implementations of the equivalent
1.41 + * functions of class {@code Math} are not defined to return the
1.42 + * bit-for-bit same results. This relaxation permits
1.43 + * better-performing implementations where strict reproducibility is
1.44 + * not required.
1.45 + *
1.46 + * <p>By default many of the {@code Math} methods simply call
1.47 + * the equivalent method in {@code StrictMath} for their
1.48 + * implementation. Code generators are encouraged to use
1.49 + * platform-specific native libraries or microprocessor instructions,
1.50 + * where available, to provide higher-performance implementations of
1.51 + * {@code Math} methods. Such higher-performance
1.52 + * implementations still must conform to the specification for
1.53 + * {@code Math}.
1.54 + *
1.55 + * <p>The quality of implementation specifications concern two
1.56 + * properties, accuracy of the returned result and monotonicity of the
1.57 + * method. Accuracy of the floating-point {@code Math} methods
1.58 + * is measured in terms of <i>ulps</i>, units in the last place. For
1.59 + * a given floating-point format, an ulp of a specific real number
1.60 + * value is the distance between the two floating-point values
1.61 + * bracketing that numerical value. When discussing the accuracy of a
1.62 + * method as a whole rather than at a specific argument, the number of
1.63 + * ulps cited is for the worst-case error at any argument. If a
1.64 + * method always has an error less than 0.5 ulps, the method always
1.65 + * returns the floating-point number nearest the exact result; such a
1.66 + * method is <i>correctly rounded</i>. A correctly rounded method is
1.67 + * generally the best a floating-point approximation can be; however,
1.68 + * it is impractical for many floating-point methods to be correctly
1.69 + * rounded. Instead, for the {@code Math} class, a larger error
1.70 + * bound of 1 or 2 ulps is allowed for certain methods. Informally,
1.71 + * with a 1 ulp error bound, when the exact result is a representable
1.72 + * number, the exact result should be returned as the computed result;
1.73 + * otherwise, either of the two floating-point values which bracket
1.74 + * the exact result may be returned. For exact results large in
1.75 + * magnitude, one of the endpoints of the bracket may be infinite.
1.76 + * Besides accuracy at individual arguments, maintaining proper
1.77 + * relations between the method at different arguments is also
1.78 + * important. Therefore, most methods with more than 0.5 ulp errors
1.79 + * are required to be <i>semi-monotonic</i>: whenever the mathematical
1.80 + * function is non-decreasing, so is the floating-point approximation,
1.81 + * likewise, whenever the mathematical function is non-increasing, so
1.82 + * is the floating-point approximation. Not all approximations that
1.83 + * have 1 ulp accuracy will automatically meet the monotonicity
1.84 + * requirements.
1.85 + *
1.86 + * @author unascribed
1.87 + * @author Joseph D. Darcy
1.88 + * @since JDK1.0
1.89 + */
1.90 +
1.91 +public final class Math {
1.92 +
1.93 + /**
1.94 + * Don't let anyone instantiate this class.
1.95 + */
1.96 + private Math() {}
1.97 +
1.98 + /**
1.99 + * The {@code double} value that is closer than any other to
1.100 + * <i>e</i>, the base of the natural logarithms.
1.101 + */
1.102 + public static final double E = 2.7182818284590452354;
1.103 +
1.104 + /**
1.105 + * The {@code double} value that is closer than any other to
1.106 + * <i>pi</i>, the ratio of the circumference of a circle to its
1.107 + * diameter.
1.108 + */
1.109 + public static final double PI = 3.14159265358979323846;
1.110 +
1.111 + /**
1.112 + * Returns the trigonometric sine of an angle. Special cases:
1.113 + * <ul><li>If the argument is NaN or an infinity, then the
1.114 + * result is NaN.
1.115 + * <li>If the argument is zero, then the result is a zero with the
1.116 + * same sign as the argument.</ul>
1.117 + *
1.118 + * <p>The computed result must be within 1 ulp of the exact result.
1.119 + * Results must be semi-monotonic.
1.120 + *
1.121 + * @param a an angle, in radians.
1.122 + * @return the sine of the argument.
1.123 + */
1.124 + @JavaScriptBody(args="a", body="return Math.sin(a);")
1.125 + public static double sin(double a) {
1.126 + throw new UnsupportedOperationException();
1.127 + }
1.128 +
1.129 + /**
1.130 + * Returns the trigonometric cosine of an angle. Special cases:
1.131 + * <ul><li>If the argument is NaN or an infinity, then the
1.132 + * result is NaN.</ul>
1.133 + *
1.134 + * <p>The computed result must be within 1 ulp of the exact result.
1.135 + * Results must be semi-monotonic.
1.136 + *
1.137 + * @param a an angle, in radians.
1.138 + * @return the cosine of the argument.
1.139 + */
1.140 + @JavaScriptBody(args="a", body="return Math.cos(a);")
1.141 + public static double cos(double a) {
1.142 + throw new UnsupportedOperationException();
1.143 + }
1.144 +
1.145 + /**
1.146 + * Returns the trigonometric tangent of an angle. Special cases:
1.147 + * <ul><li>If the argument is NaN or an infinity, then the result
1.148 + * is NaN.
1.149 + * <li>If the argument is zero, then the result is a zero with the
1.150 + * same sign as the argument.</ul>
1.151 + *
1.152 + * <p>The computed result must be within 1 ulp of the exact result.
1.153 + * Results must be semi-monotonic.
1.154 + *
1.155 + * @param a an angle, in radians.
1.156 + * @return the tangent of the argument.
1.157 + */
1.158 + @JavaScriptBody(args="a", body="return Math.tan(a);")
1.159 + public static double tan(double a) {
1.160 + throw new UnsupportedOperationException();
1.161 + }
1.162 +
1.163 + /**
1.164 + * Returns the arc sine of a value; the returned angle is in the
1.165 + * range -<i>pi</i>/2 through <i>pi</i>/2. Special cases:
1.166 + * <ul><li>If the argument is NaN or its absolute value is greater
1.167 + * than 1, then the result is NaN.
1.168 + * <li>If the argument is zero, then the result is a zero with the
1.169 + * same sign as the argument.</ul>
1.170 + *
1.171 + * <p>The computed result must be within 1 ulp of the exact result.
1.172 + * Results must be semi-monotonic.
1.173 + *
1.174 + * @param a the value whose arc sine is to be returned.
1.175 + * @return the arc sine of the argument.
1.176 + */
1.177 + @JavaScriptBody(args="a", body="return Math.asin(a);")
1.178 + public static double asin(double a) {
1.179 + throw new UnsupportedOperationException();
1.180 + }
1.181 +
1.182 + /**
1.183 + * Returns the arc cosine of a value; the returned angle is in the
1.184 + * range 0.0 through <i>pi</i>. Special case:
1.185 + * <ul><li>If the argument is NaN or its absolute value is greater
1.186 + * than 1, then the result is NaN.</ul>
1.187 + *
1.188 + * <p>The computed result must be within 1 ulp of the exact result.
1.189 + * Results must be semi-monotonic.
1.190 + *
1.191 + * @param a the value whose arc cosine is to be returned.
1.192 + * @return the arc cosine of the argument.
1.193 + */
1.194 + @JavaScriptBody(args="a", body="return Math.acos(a);")
1.195 + public static double acos(double a) {
1.196 + throw new UnsupportedOperationException();
1.197 + }
1.198 +
1.199 + /**
1.200 + * Returns the arc tangent of a value; the returned angle is in the
1.201 + * range -<i>pi</i>/2 through <i>pi</i>/2. Special cases:
1.202 + * <ul><li>If the argument is NaN, then the result is NaN.
1.203 + * <li>If the argument is zero, then the result is a zero with the
1.204 + * same sign as the argument.</ul>
1.205 + *
1.206 + * <p>The computed result must be within 1 ulp of the exact result.
1.207 + * Results must be semi-monotonic.
1.208 + *
1.209 + * @param a the value whose arc tangent is to be returned.
1.210 + * @return the arc tangent of the argument.
1.211 + */
1.212 + @JavaScriptBody(args="a", body="return Math.atan(a);")
1.213 + public static double atan(double a) {
1.214 + throw new UnsupportedOperationException();
1.215 + }
1.216 +
1.217 + /**
1.218 + * Converts an angle measured in degrees to an approximately
1.219 + * equivalent angle measured in radians. The conversion from
1.220 + * degrees to radians is generally inexact.
1.221 + *
1.222 + * @param angdeg an angle, in degrees
1.223 + * @return the measurement of the angle {@code angdeg}
1.224 + * in radians.
1.225 + * @since 1.2
1.226 + */
1.227 + public static double toRadians(double angdeg) {
1.228 + return angdeg / 180.0 * PI;
1.229 + }
1.230 +
1.231 + /**
1.232 + * Converts an angle measured in radians to an approximately
1.233 + * equivalent angle measured in degrees. The conversion from
1.234 + * radians to degrees is generally inexact; users should
1.235 + * <i>not</i> expect {@code cos(toRadians(90.0))} to exactly
1.236 + * equal {@code 0.0}.
1.237 + *
1.238 + * @param angrad an angle, in radians
1.239 + * @return the measurement of the angle {@code angrad}
1.240 + * in degrees.
1.241 + * @since 1.2
1.242 + */
1.243 + public static double toDegrees(double angrad) {
1.244 + return angrad * 180.0 / PI;
1.245 + }
1.246 +
1.247 + /**
1.248 + * Returns Euler's number <i>e</i> raised to the power of a
1.249 + * {@code double} value. Special cases:
1.250 + * <ul><li>If the argument is NaN, the result is NaN.
1.251 + * <li>If the argument is positive infinity, then the result is
1.252 + * positive infinity.
1.253 + * <li>If the argument is negative infinity, then the result is
1.254 + * positive zero.</ul>
1.255 + *
1.256 + * <p>The computed result must be within 1 ulp of the exact result.
1.257 + * Results must be semi-monotonic.
1.258 + *
1.259 + * @param a the exponent to raise <i>e</i> to.
1.260 + * @return the value <i>e</i><sup>{@code a}</sup>,
1.261 + * where <i>e</i> is the base of the natural logarithms.
1.262 + */
1.263 + @JavaScriptBody(args="a", body="return Math.exp(a);")
1.264 + public static double exp(double a) {
1.265 + throw new UnsupportedOperationException();
1.266 + }
1.267 +
1.268 + /**
1.269 + * Returns the natural logarithm (base <i>e</i>) of a {@code double}
1.270 + * value. Special cases:
1.271 + * <ul><li>If the argument is NaN or less than zero, then the result
1.272 + * is NaN.
1.273 + * <li>If the argument is positive infinity, then the result is
1.274 + * positive infinity.
1.275 + * <li>If the argument is positive zero or negative zero, then the
1.276 + * result is negative infinity.</ul>
1.277 + *
1.278 + * <p>The computed result must be within 1 ulp of the exact result.
1.279 + * Results must be semi-monotonic.
1.280 + *
1.281 + * @param a a value
1.282 + * @return the value ln {@code a}, the natural logarithm of
1.283 + * {@code a}.
1.284 + */
1.285 + @JavaScriptBody(args="a", body="return Math.log(a);")
1.286 + public static double log(double a) {
1.287 + throw new UnsupportedOperationException();
1.288 + }
1.289 +
1.290 + /**
1.291 + * Returns the base 10 logarithm of a {@code double} value.
1.292 + * Special cases:
1.293 + *
1.294 + * <ul><li>If the argument is NaN or less than zero, then the result
1.295 + * is NaN.
1.296 + * <li>If the argument is positive infinity, then the result is
1.297 + * positive infinity.
1.298 + * <li>If the argument is positive zero or negative zero, then the
1.299 + * result is negative infinity.
1.300 + * <li> If the argument is equal to 10<sup><i>n</i></sup> for
1.301 + * integer <i>n</i>, then the result is <i>n</i>.
1.302 + * </ul>
1.303 + *
1.304 + * <p>The computed result must be within 1 ulp of the exact result.
1.305 + * Results must be semi-monotonic.
1.306 + *
1.307 + * @param a a value
1.308 + * @return the base 10 logarithm of {@code a}.
1.309 + * @since 1.5
1.310 + */
1.311 + @JavaScriptBody(args="a", body="return Math.log(a) / Math.LN10;")
1.312 + public static double log10(double a) {
1.313 + throw new UnsupportedOperationException();
1.314 + }
1.315 +
1.316 + /**
1.317 + * Returns the correctly rounded positive square root of a
1.318 + * {@code double} value.
1.319 + * Special cases:
1.320 + * <ul><li>If the argument is NaN or less than zero, then the result
1.321 + * is NaN.
1.322 + * <li>If the argument is positive infinity, then the result is positive
1.323 + * infinity.
1.324 + * <li>If the argument is positive zero or negative zero, then the
1.325 + * result is the same as the argument.</ul>
1.326 + * Otherwise, the result is the {@code double} value closest to
1.327 + * the true mathematical square root of the argument value.
1.328 + *
1.329 + * @param a a value.
1.330 + * @return the positive square root of {@code a}.
1.331 + * If the argument is NaN or less than zero, the result is NaN.
1.332 + */
1.333 + @JavaScriptBody(args="a", body="return Math.sqrt(a);")
1.334 + public static double sqrt(double a) {
1.335 + throw new UnsupportedOperationException();
1.336 + }
1.337 +
1.338 + /**
1.339 + * Returns the smallest (closest to negative infinity)
1.340 + * {@code double} value that is greater than or equal to the
1.341 + * argument and is equal to a mathematical integer. Special cases:
1.342 + * <ul><li>If the argument value is already equal to a
1.343 + * mathematical integer, then the result is the same as the
1.344 + * argument. <li>If the argument is NaN or an infinity or
1.345 + * positive zero or negative zero, then the result is the same as
1.346 + * the argument. <li>If the argument value is less than zero but
1.347 + * greater than -1.0, then the result is negative zero.</ul> Note
1.348 + * that the value of {@code Math.ceil(x)} is exactly the
1.349 + * value of {@code -Math.floor(-x)}.
1.350 + *
1.351 + *
1.352 + * @param a a value.
1.353 + * @return the smallest (closest to negative infinity)
1.354 + * floating-point value that is greater than or equal to
1.355 + * the argument and is equal to a mathematical integer.
1.356 + */
1.357 + @JavaScriptBody(args="a", body="return Math.ceil(a);")
1.358 + public static double ceil(double a) {
1.359 + throw new UnsupportedOperationException();
1.360 + }
1.361 +
1.362 + /**
1.363 + * Returns the largest (closest to positive infinity)
1.364 + * {@code double} value that is less than or equal to the
1.365 + * argument and is equal to a mathematical integer. Special cases:
1.366 + * <ul><li>If the argument value is already equal to a
1.367 + * mathematical integer, then the result is the same as the
1.368 + * argument. <li>If the argument is NaN or an infinity or
1.369 + * positive zero or negative zero, then the result is the same as
1.370 + * the argument.</ul>
1.371 + *
1.372 + * @param a a value.
1.373 + * @return the largest (closest to positive infinity)
1.374 + * floating-point value that less than or equal to the argument
1.375 + * and is equal to a mathematical integer.
1.376 + */
1.377 + @JavaScriptBody(args="a", body="return Math.floor(a);")
1.378 + public static double floor(double a) {
1.379 + throw new UnsupportedOperationException();
1.380 + }
1.381 + /**
1.382 + * Computes the remainder operation on two arguments as prescribed
1.383 + * by the IEEE 754 standard.
1.384 + * The remainder value is mathematically equal to
1.385 + * <code>f1 - f2</code> × <i>n</i>,
1.386 + * where <i>n</i> is the mathematical integer closest to the exact
1.387 + * mathematical value of the quotient {@code f1/f2}, and if two
1.388 + * mathematical integers are equally close to {@code f1/f2},
1.389 + * then <i>n</i> is the integer that is even. If the remainder is
1.390 + * zero, its sign is the same as the sign of the first argument.
1.391 + * Special cases:
1.392 + * <ul><li>If either argument is NaN, or the first argument is infinite,
1.393 + * or the second argument is positive zero or negative zero, then the
1.394 + * result is NaN.
1.395 + * <li>If the first argument is finite and the second argument is
1.396 + * infinite, then the result is the same as the first argument.</ul>
1.397 + *
1.398 + * @param f1 the dividend.
1.399 + * @param f2 the divisor.
1.400 + * @return the remainder when {@code f1} is divided by
1.401 + * {@code f2}.
1.402 + */
1.403 + public static double IEEEremainder(double f1, double f2) {
1.404 + return f1 - (f2 * Math.round(f1 / f2));
1.405 + }
1.406 +
1.407 + /**
1.408 + * Returns the {@code double} value that is closest in value
1.409 + * to the argument and is equal to a mathematical integer. If two
1.410 + * {@code double} values that are mathematical integers are
1.411 + * equally close, the result is the integer value that is
1.412 + * even. Special cases:
1.413 + * <ul><li>If the argument value is already equal to a mathematical
1.414 + * integer, then the result is the same as the argument.
1.415 + * <li>If the argument is NaN or an infinity or positive zero or negative
1.416 + * zero, then the result is the same as the argument.</ul>
1.417 + *
1.418 + * @param a a {@code double} value.
1.419 + * @return the closest floating-point value to {@code a} that is
1.420 + * equal to a mathematical integer.
1.421 + */
1.422 + public static double rint(double a) {
1.423 + double ceil = ceil(a);
1.424 + double floor = floor(a);
1.425 +
1.426 + double dc = ceil - a;
1.427 + double df = a - floor;
1.428 +
1.429 + if (dc < df) {
1.430 + return ceil;
1.431 + } else if (dc > df) {
1.432 + return floor;
1.433 + }
1.434 +
1.435 + int tenC = (int) (ceil % 10.0);
1.436 +
1.437 + if (tenC % 2 == 0) {
1.438 + return ceil;
1.439 + } else {
1.440 + return floor;
1.441 + }
1.442 + }
1.443 +
1.444 + /**
1.445 + * Returns the angle <i>theta</i> from the conversion of rectangular
1.446 + * coordinates ({@code x}, {@code y}) to polar
1.447 + * coordinates (r, <i>theta</i>).
1.448 + * This method computes the phase <i>theta</i> by computing an arc tangent
1.449 + * of {@code y/x} in the range of -<i>pi</i> to <i>pi</i>. Special
1.450 + * cases:
1.451 + * <ul><li>If either argument is NaN, then the result is NaN.
1.452 + * <li>If the first argument is positive zero and the second argument
1.453 + * is positive, or the first argument is positive and finite and the
1.454 + * second argument is positive infinity, then the result is positive
1.455 + * zero.
1.456 + * <li>If the first argument is negative zero and the second argument
1.457 + * is positive, or the first argument is negative and finite and the
1.458 + * second argument is positive infinity, then the result is negative zero.
1.459 + * <li>If the first argument is positive zero and the second argument
1.460 + * is negative, or the first argument is positive and finite and the
1.461 + * second argument is negative infinity, then the result is the
1.462 + * {@code double} value closest to <i>pi</i>.
1.463 + * <li>If the first argument is negative zero and the second argument
1.464 + * is negative, or the first argument is negative and finite and the
1.465 + * second argument is negative infinity, then the result is the
1.466 + * {@code double} value closest to -<i>pi</i>.
1.467 + * <li>If the first argument is positive and the second argument is
1.468 + * positive zero or negative zero, or the first argument is positive
1.469 + * infinity and the second argument is finite, then the result is the
1.470 + * {@code double} value closest to <i>pi</i>/2.
1.471 + * <li>If the first argument is negative and the second argument is
1.472 + * positive zero or negative zero, or the first argument is negative
1.473 + * infinity and the second argument is finite, then the result is the
1.474 + * {@code double} value closest to -<i>pi</i>/2.
1.475 + * <li>If both arguments are positive infinity, then the result is the
1.476 + * {@code double} value closest to <i>pi</i>/4.
1.477 + * <li>If the first argument is positive infinity and the second argument
1.478 + * is negative infinity, then the result is the {@code double}
1.479 + * value closest to 3*<i>pi</i>/4.
1.480 + * <li>If the first argument is negative infinity and the second argument
1.481 + * is positive infinity, then the result is the {@code double} value
1.482 + * closest to -<i>pi</i>/4.
1.483 + * <li>If both arguments are negative infinity, then the result is the
1.484 + * {@code double} value closest to -3*<i>pi</i>/4.</ul>
1.485 + *
1.486 + * <p>The computed result must be within 2 ulps of the exact result.
1.487 + * Results must be semi-monotonic.
1.488 + *
1.489 + * @param y the ordinate coordinate
1.490 + * @param x the abscissa coordinate
1.491 + * @return the <i>theta</i> component of the point
1.492 + * (<i>r</i>, <i>theta</i>)
1.493 + * in polar coordinates that corresponds to the point
1.494 + * (<i>x</i>, <i>y</i>) in Cartesian coordinates.
1.495 + */
1.496 + @JavaScriptBody(args={"y", "x"}, body="return Math.atan2(y, x);")
1.497 + public static double atan2(double y, double x) {
1.498 + throw new UnsupportedOperationException();
1.499 + }
1.500 +
1.501 + /**
1.502 + * Returns the value of the first argument raised to the power of the
1.503 + * second argument. Special cases:
1.504 + *
1.505 + * <ul><li>If the second argument is positive or negative zero, then the
1.506 + * result is 1.0.
1.507 + * <li>If the second argument is 1.0, then the result is the same as the
1.508 + * first argument.
1.509 + * <li>If the second argument is NaN, then the result is NaN.
1.510 + * <li>If the first argument is NaN and the second argument is nonzero,
1.511 + * then the result is NaN.
1.512 + *
1.513 + * <li>If
1.514 + * <ul>
1.515 + * <li>the absolute value of the first argument is greater than 1
1.516 + * and the second argument is positive infinity, or
1.517 + * <li>the absolute value of the first argument is less than 1 and
1.518 + * the second argument is negative infinity,
1.519 + * </ul>
1.520 + * then the result is positive infinity.
1.521 + *
1.522 + * <li>If
1.523 + * <ul>
1.524 + * <li>the absolute value of the first argument is greater than 1 and
1.525 + * the second argument is negative infinity, or
1.526 + * <li>the absolute value of the
1.527 + * first argument is less than 1 and the second argument is positive
1.528 + * infinity,
1.529 + * </ul>
1.530 + * then the result is positive zero.
1.531 + *
1.532 + * <li>If the absolute value of the first argument equals 1 and the
1.533 + * second argument is infinite, then the result is NaN.
1.534 + *
1.535 + * <li>If
1.536 + * <ul>
1.537 + * <li>the first argument is positive zero and the second argument
1.538 + * is greater than zero, or
1.539 + * <li>the first argument is positive infinity and the second
1.540 + * argument is less than zero,
1.541 + * </ul>
1.542 + * then the result is positive zero.
1.543 + *
1.544 + * <li>If
1.545 + * <ul>
1.546 + * <li>the first argument is positive zero and the second argument
1.547 + * is less than zero, or
1.548 + * <li>the first argument is positive infinity and the second
1.549 + * argument is greater than zero,
1.550 + * </ul>
1.551 + * then the result is positive infinity.
1.552 + *
1.553 + * <li>If
1.554 + * <ul>
1.555 + * <li>the first argument is negative zero and the second argument
1.556 + * is greater than zero but not a finite odd integer, or
1.557 + * <li>the first argument is negative infinity and the second
1.558 + * argument is less than zero but not a finite odd integer,
1.559 + * </ul>
1.560 + * then the result is positive zero.
1.561 + *
1.562 + * <li>If
1.563 + * <ul>
1.564 + * <li>the first argument is negative zero and the second argument
1.565 + * is a positive finite odd integer, or
1.566 + * <li>the first argument is negative infinity and the second
1.567 + * argument is a negative finite odd integer,
1.568 + * </ul>
1.569 + * then the result is negative zero.
1.570 + *
1.571 + * <li>If
1.572 + * <ul>
1.573 + * <li>the first argument is negative zero and the second argument
1.574 + * is less than zero but not a finite odd integer, or
1.575 + * <li>the first argument is negative infinity and the second
1.576 + * argument is greater than zero but not a finite odd integer,
1.577 + * </ul>
1.578 + * then the result is positive infinity.
1.579 + *
1.580 + * <li>If
1.581 + * <ul>
1.582 + * <li>the first argument is negative zero and the second argument
1.583 + * is a negative finite odd integer, or
1.584 + * <li>the first argument is negative infinity and the second
1.585 + * argument is a positive finite odd integer,
1.586 + * </ul>
1.587 + * then the result is negative infinity.
1.588 + *
1.589 + * <li>If the first argument is finite and less than zero
1.590 + * <ul>
1.591 + * <li> if the second argument is a finite even integer, the
1.592 + * result is equal to the result of raising the absolute value of
1.593 + * the first argument to the power of the second argument
1.594 + *
1.595 + * <li>if the second argument is a finite odd integer, the result
1.596 + * is equal to the negative of the result of raising the absolute
1.597 + * value of the first argument to the power of the second
1.598 + * argument
1.599 + *
1.600 + * <li>if the second argument is finite and not an integer, then
1.601 + * the result is NaN.
1.602 + * </ul>
1.603 + *
1.604 + * <li>If both arguments are integers, then the result is exactly equal
1.605 + * to the mathematical result of raising the first argument to the power
1.606 + * of the second argument if that result can in fact be represented
1.607 + * exactly as a {@code double} value.</ul>
1.608 + *
1.609 + * <p>(In the foregoing descriptions, a floating-point value is
1.610 + * considered to be an integer if and only if it is finite and a
1.611 + * fixed point of the method {@link #ceil ceil} or,
1.612 + * equivalently, a fixed point of the method {@link #floor
1.613 + * floor}. A value is a fixed point of a one-argument
1.614 + * method if and only if the result of applying the method to the
1.615 + * value is equal to the value.)
1.616 + *
1.617 + * <p>The computed result must be within 1 ulp of the exact result.
1.618 + * Results must be semi-monotonic.
1.619 + *
1.620 + * @param a the base.
1.621 + * @param b the exponent.
1.622 + * @return the value {@code a}<sup>{@code b}</sup>.
1.623 + */
1.624 + @JavaScriptBody(args={"a", "b"}, body="return Math.pow(a, b);")
1.625 + public static double pow(double a, double b) {
1.626 + throw new UnsupportedOperationException();
1.627 + }
1.628 +
1.629 + /**
1.630 + * Returns the closest {@code int} to the argument, with ties
1.631 + * rounding up.
1.632 + *
1.633 + * <p>
1.634 + * Special cases:
1.635 + * <ul><li>If the argument is NaN, the result is 0.
1.636 + * <li>If the argument is negative infinity or any value less than or
1.637 + * equal to the value of {@code Integer.MIN_VALUE}, the result is
1.638 + * equal to the value of {@code Integer.MIN_VALUE}.
1.639 + * <li>If the argument is positive infinity or any value greater than or
1.640 + * equal to the value of {@code Integer.MAX_VALUE}, the result is
1.641 + * equal to the value of {@code Integer.MAX_VALUE}.</ul>
1.642 + *
1.643 + * @param a a floating-point value to be rounded to an integer.
1.644 + * @return the value of the argument rounded to the nearest
1.645 + * {@code int} value.
1.646 + * @see java.lang.Integer#MAX_VALUE
1.647 + * @see java.lang.Integer#MIN_VALUE
1.648 + */
1.649 + public static int round(float a) {
1.650 + return (int)roundDbl(a);
1.651 + }
1.652 +
1.653 + /**
1.654 + * Returns the closest {@code long} to the argument, with ties
1.655 + * rounding up.
1.656 + *
1.657 + * <p>Special cases:
1.658 + * <ul><li>If the argument is NaN, the result is 0.
1.659 + * <li>If the argument is negative infinity or any value less than or
1.660 + * equal to the value of {@code Long.MIN_VALUE}, the result is
1.661 + * equal to the value of {@code Long.MIN_VALUE}.
1.662 + * <li>If the argument is positive infinity or any value greater than or
1.663 + * equal to the value of {@code Long.MAX_VALUE}, the result is
1.664 + * equal to the value of {@code Long.MAX_VALUE}.</ul>
1.665 + *
1.666 + * @param a a floating-point value to be rounded to a
1.667 + * {@code long}.
1.668 + * @return the value of the argument rounded to the nearest
1.669 + * {@code long} value.
1.670 + * @see java.lang.Long#MAX_VALUE
1.671 + * @see java.lang.Long#MIN_VALUE
1.672 + */
1.673 + public static long round(double a) {
1.674 + return (long)roundDbl(a);
1.675 + }
1.676 +
1.677 + @JavaScriptBody(args="a", body="return Math.round(a);")
1.678 + private static native double roundDbl(double d);
1.679 +
1.680 +// private static Random randomNumberGenerator;
1.681 +//
1.682 +// private static synchronized Random initRNG() {
1.683 +// Random rnd = randomNumberGenerator;
1.684 +// return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd;
1.685 +// }
1.686 +
1.687 + /**
1.688 + * Returns a {@code double} value with a positive sign, greater
1.689 + * than or equal to {@code 0.0} and less than {@code 1.0}.
1.690 + * Returned values are chosen pseudorandomly with (approximately)
1.691 + * uniform distribution from that range.
1.692 + *
1.693 + * <p>When this method is first called, it creates a single new
1.694 + * pseudorandom-number generator, exactly as if by the expression
1.695 + *
1.696 + * <blockquote>{@code new java.util.Random()}</blockquote>
1.697 + *
1.698 + * This new pseudorandom-number generator is used thereafter for
1.699 + * all calls to this method and is used nowhere else.
1.700 + *
1.701 + * <p>This method is properly synchronized to allow correct use by
1.702 + * more than one thread. However, if many threads need to generate
1.703 + * pseudorandom numbers at a great rate, it may reduce contention
1.704 + * for each thread to have its own pseudorandom-number generator.
1.705 + *
1.706 + * @return a pseudorandom {@code double} greater than or equal
1.707 + * to {@code 0.0} and less than {@code 1.0}.
1.708 + * @see Random#nextDouble()
1.709 + */
1.710 + @JavaScriptBody(args={}, body="return Math.random();")
1.711 + public static double random() {
1.712 + throw new UnsupportedOperationException();
1.713 + }
1.714 +
1.715 + /**
1.716 + * Returns the absolute value of an {@code int} value.
1.717 + * If the argument is not negative, the argument is returned.
1.718 + * If the argument is negative, the negation of the argument is returned.
1.719 + *
1.720 + * <p>Note that if the argument is equal to the value of
1.721 + * {@link Integer#MIN_VALUE}, the most negative representable
1.722 + * {@code int} value, the result is that same value, which is
1.723 + * negative.
1.724 + *
1.725 + * @param a the argument whose absolute value is to be determined
1.726 + * @return the absolute value of the argument.
1.727 + */
1.728 + public static int abs(int a) {
1.729 + return (a < 0) ? -a : a;
1.730 + }
1.731 +
1.732 + /**
1.733 + * Returns the absolute value of a {@code long} value.
1.734 + * If the argument is not negative, the argument is returned.
1.735 + * If the argument is negative, the negation of the argument is returned.
1.736 + *
1.737 + * <p>Note that if the argument is equal to the value of
1.738 + * {@link Long#MIN_VALUE}, the most negative representable
1.739 + * {@code long} value, the result is that same value, which
1.740 + * is negative.
1.741 + *
1.742 + * @param a the argument whose absolute value is to be determined
1.743 + * @return the absolute value of the argument.
1.744 + */
1.745 + public static long abs(long a) {
1.746 + return (a < 0) ? -a : a;
1.747 + }
1.748 +
1.749 + /**
1.750 + * Returns the absolute value of a {@code float} value.
1.751 + * If the argument is not negative, the argument is returned.
1.752 + * If the argument is negative, the negation of the argument is returned.
1.753 + * Special cases:
1.754 + * <ul><li>If the argument is positive zero or negative zero, the
1.755 + * result is positive zero.
1.756 + * <li>If the argument is infinite, the result is positive infinity.
1.757 + * <li>If the argument is NaN, the result is NaN.</ul>
1.758 + * In other words, the result is the same as the value of the expression:
1.759 + * <p>{@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
1.760 + *
1.761 + * @param a the argument whose absolute value is to be determined
1.762 + * @return the absolute value of the argument.
1.763 + */
1.764 + public static float abs(float a) {
1.765 + return (a <= 0.0F) ? 0.0F - a : a;
1.766 + }
1.767 +
1.768 + /**
1.769 + * Returns the absolute value of a {@code double} value.
1.770 + * If the argument is not negative, the argument is returned.
1.771 + * If the argument is negative, the negation of the argument is returned.
1.772 + * Special cases:
1.773 + * <ul><li>If the argument is positive zero or negative zero, the result
1.774 + * is positive zero.
1.775 + * <li>If the argument is infinite, the result is positive infinity.
1.776 + * <li>If the argument is NaN, the result is NaN.</ul>
1.777 + * In other words, the result is the same as the value of the expression:
1.778 + * <p>{@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
1.779 + *
1.780 + * @param a the argument whose absolute value is to be determined
1.781 + * @return the absolute value of the argument.
1.782 + */
1.783 + public static double abs(double a) {
1.784 + return (a <= 0.0D) ? 0.0D - a : a;
1.785 + }
1.786 +
1.787 + /**
1.788 + * Returns the greater of two {@code int} values. That is, the
1.789 + * result is the argument closer to the value of
1.790 + * {@link Integer#MAX_VALUE}. If the arguments have the same value,
1.791 + * the result is that same value.
1.792 + *
1.793 + * @param a an argument.
1.794 + * @param b another argument.
1.795 + * @return the larger of {@code a} and {@code b}.
1.796 + */
1.797 + public static int max(int a, int b) {
1.798 + return (a >= b) ? a : b;
1.799 + }
1.800 +
1.801 + /**
1.802 + * Returns the greater of two {@code long} values. That is, the
1.803 + * result is the argument closer to the value of
1.804 + * {@link Long#MAX_VALUE}. If the arguments have the same value,
1.805 + * the result is that same value.
1.806 + *
1.807 + * @param a an argument.
1.808 + * @param b another argument.
1.809 + * @return the larger of {@code a} and {@code b}.
1.810 + */
1.811 + public static long max(long a, long b) {
1.812 + return (a >= b) ? a : b;
1.813 + }
1.814 +
1.815 + /**
1.816 + * Returns the greater of two {@code float} values. That is,
1.817 + * the result is the argument closer to positive infinity. If the
1.818 + * arguments have the same value, the result is that same
1.819 + * value. If either value is NaN, then the result is NaN. Unlike
1.820 + * the numerical comparison operators, this method considers
1.821 + * negative zero to be strictly smaller than positive zero. If one
1.822 + * argument is positive zero and the other negative zero, the
1.823 + * result is positive zero.
1.824 + *
1.825 + * @param a an argument.
1.826 + * @param b another argument.
1.827 + * @return the larger of {@code a} and {@code b}.
1.828 + */
1.829 + @JavaScriptBody(args={"a", "b"},
1.830 + body="return Math.max(a,b);"
1.831 + )
1.832 + public static float max(float a, float b) {
1.833 + throw new UnsupportedOperationException();
1.834 + }
1.835 +
1.836 + /**
1.837 + * Returns the greater of two {@code double} values. That
1.838 + * is, the result is the argument closer to positive infinity. If
1.839 + * the arguments have the same value, the result is that same
1.840 + * value. If either value is NaN, then the result is NaN. Unlike
1.841 + * the numerical comparison operators, this method considers
1.842 + * negative zero to be strictly smaller than positive zero. If one
1.843 + * argument is positive zero and the other negative zero, the
1.844 + * result is positive zero.
1.845 + *
1.846 + * @param a an argument.
1.847 + * @param b another argument.
1.848 + * @return the larger of {@code a} and {@code b}.
1.849 + */
1.850 + @JavaScriptBody(args={"a", "b"},
1.851 + body="return Math.max(a,b);"
1.852 + )
1.853 + public static double max(double a, double b) {
1.854 + throw new UnsupportedOperationException();
1.855 + }
1.856 +
1.857 + /**
1.858 + * Returns the smaller of two {@code int} values. That is,
1.859 + * the result the argument closer to the value of
1.860 + * {@link Integer#MIN_VALUE}. If the arguments have the same
1.861 + * value, the result is that same value.
1.862 + *
1.863 + * @param a an argument.
1.864 + * @param b another argument.
1.865 + * @return the smaller of {@code a} and {@code b}.
1.866 + */
1.867 + public static int min(int a, int b) {
1.868 + return (a <= b) ? a : b;
1.869 + }
1.870 +
1.871 + /**
1.872 + * Returns the smaller of two {@code long} values. That is,
1.873 + * the result is the argument closer to the value of
1.874 + * {@link Long#MIN_VALUE}. If the arguments have the same
1.875 + * value, the result is that same value.
1.876 + *
1.877 + * @param a an argument.
1.878 + * @param b another argument.
1.879 + * @return the smaller of {@code a} and {@code b}.
1.880 + */
1.881 + public static long min(long a, long b) {
1.882 + return (a <= b) ? a : b;
1.883 + }
1.884 +
1.885 + /**
1.886 + * Returns the smaller of two {@code float} values. That is,
1.887 + * the result is the value closer to negative infinity. If the
1.888 + * arguments have the same value, the result is that same
1.889 + * value. If either value is NaN, then the result is NaN. Unlike
1.890 + * the numerical comparison operators, this method considers
1.891 + * negative zero to be strictly smaller than positive zero. If
1.892 + * one argument is positive zero and the other is negative zero,
1.893 + * the result is negative zero.
1.894 + *
1.895 + * @param a an argument.
1.896 + * @param b another argument.
1.897 + * @return the smaller of {@code a} and {@code b}.
1.898 + */
1.899 + @JavaScriptBody(args={"a", "b"},
1.900 + body="return Math.min(a,b);"
1.901 + )
1.902 + public static float min(float a, float b) {
1.903 + throw new UnsupportedOperationException();
1.904 + }
1.905 +
1.906 + /**
1.907 + * Returns the smaller of two {@code double} values. That
1.908 + * is, the result is the value closer to negative infinity. If the
1.909 + * arguments have the same value, the result is that same
1.910 + * value. If either value is NaN, then the result is NaN. Unlike
1.911 + * the numerical comparison operators, this method considers
1.912 + * negative zero to be strictly smaller than positive zero. If one
1.913 + * argument is positive zero and the other is negative zero, the
1.914 + * result is negative zero.
1.915 + *
1.916 + * @param a an argument.
1.917 + * @param b another argument.
1.918 + * @return the smaller of {@code a} and {@code b}.
1.919 + */
1.920 + @JavaScriptBody(args={"a", "b"},
1.921 + body="return Math.min(a,b);"
1.922 + )
1.923 + public static double min(double a, double b) {
1.924 + throw new UnsupportedOperationException();
1.925 + }
1.926 +
1.927 + /**
1.928 + * Returns the size of an ulp of the argument. An ulp of a
1.929 + * {@code double} value is the positive distance between this
1.930 + * floating-point value and the {@code double} value next
1.931 + * larger in magnitude. Note that for non-NaN <i>x</i>,
1.932 + * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
1.933 + *
1.934 + * <p>Special Cases:
1.935 + * <ul>
1.936 + * <li> If the argument is NaN, then the result is NaN.
1.937 + * <li> If the argument is positive or negative infinity, then the
1.938 + * result is positive infinity.
1.939 + * <li> If the argument is positive or negative zero, then the result is
1.940 + * {@code Double.MIN_VALUE}.
1.941 + * <li> If the argument is ±{@code Double.MAX_VALUE}, then
1.942 + * the result is equal to 2<sup>971</sup>.
1.943 + * </ul>
1.944 + *
1.945 + * @param d the floating-point value whose ulp is to be returned
1.946 + * @return the size of an ulp of the argument
1.947 + * @author Joseph D. Darcy
1.948 + * @since 1.5
1.949 + */
1.950 +// public static double ulp(double d) {
1.951 +// return sun.misc.FpUtils.ulp(d);
1.952 +// }
1.953 +
1.954 + /**
1.955 + * Returns the size of an ulp of the argument. An ulp of a
1.956 + * {@code float} value is the positive distance between this
1.957 + * floating-point value and the {@code float} value next
1.958 + * larger in magnitude. Note that for non-NaN <i>x</i>,
1.959 + * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
1.960 + *
1.961 + * <p>Special Cases:
1.962 + * <ul>
1.963 + * <li> If the argument is NaN, then the result is NaN.
1.964 + * <li> If the argument is positive or negative infinity, then the
1.965 + * result is positive infinity.
1.966 + * <li> If the argument is positive or negative zero, then the result is
1.967 + * {@code Float.MIN_VALUE}.
1.968 + * <li> If the argument is ±{@code Float.MAX_VALUE}, then
1.969 + * the result is equal to 2<sup>104</sup>.
1.970 + * </ul>
1.971 + *
1.972 + * @param f the floating-point value whose ulp is to be returned
1.973 + * @return the size of an ulp of the argument
1.974 + * @author Joseph D. Darcy
1.975 + * @since 1.5
1.976 + */
1.977 +// public static float ulp(float f) {
1.978 +// return sun.misc.FpUtils.ulp(f);
1.979 +// }
1.980 +
1.981 + /**
1.982 + * Returns the signum function of the argument; zero if the argument
1.983 + * is zero, 1.0 if the argument is greater than zero, -1.0 if the
1.984 + * argument is less than zero.
1.985 + *
1.986 + * <p>Special Cases:
1.987 + * <ul>
1.988 + * <li> If the argument is NaN, then the result is NaN.
1.989 + * <li> If the argument is positive zero or negative zero, then the
1.990 + * result is the same as the argument.
1.991 + * </ul>
1.992 + *
1.993 + * @param d the floating-point value whose signum is to be returned
1.994 + * @return the signum function of the argument
1.995 + * @author Joseph D. Darcy
1.996 + * @since 1.5
1.997 + */
1.998 + public static double signum(double d) {
1.999 + if (d < 0.0) { return -1.0; }
1.1000 + if (d > 0.0) { return 1.0; }
1.1001 + return d;
1.1002 + }
1.1003 +
1.1004 + /**
1.1005 + * Returns the signum function of the argument; zero if the argument
1.1006 + * is zero, 1.0f if the argument is greater than zero, -1.0f if the
1.1007 + * argument is less than zero.
1.1008 + *
1.1009 + * <p>Special Cases:
1.1010 + * <ul>
1.1011 + * <li> If the argument is NaN, then the result is NaN.
1.1012 + * <li> If the argument is positive zero or negative zero, then the
1.1013 + * result is the same as the argument.
1.1014 + * </ul>
1.1015 + *
1.1016 + * @param f the floating-point value whose signum is to be returned
1.1017 + * @return the signum function of the argument
1.1018 + * @author Joseph D. Darcy
1.1019 + * @since 1.5
1.1020 + */
1.1021 + public static float signum(float f) {
1.1022 + if (f < 0.0f) { return -1.0f; }
1.1023 + if (f > 0.0f) { return 1.0f; }
1.1024 + return f;
1.1025 + }
1.1026 +
1.1027 + /**
1.1028 + * Returns the first floating-point argument with the sign of the
1.1029 + * second floating-point argument. Note that unlike the {@link
1.1030 + * StrictMath#copySign(double, double) StrictMath.copySign}
1.1031 + * method, this method does not require NaN {@code sign}
1.1032 + * arguments to be treated as positive values; implementations are
1.1033 + * permitted to treat some NaN arguments as positive and other NaN
1.1034 + * arguments as negative to allow greater performance.
1.1035 + *
1.1036 + * @param magnitude the parameter providing the magnitude of the result
1.1037 + * @param sign the parameter providing the sign of the result
1.1038 + * @return a value with the magnitude of {@code magnitude}
1.1039 + * and the sign of {@code sign}.
1.1040 + * @since 1.6
1.1041 + */
1.1042 +// public static double copySign(double magnitude, double sign) {
1.1043 +// return sun.misc.FpUtils.rawCopySign(magnitude, sign);
1.1044 +// }
1.1045 +
1.1046 + /**
1.1047 + * Returns the first floating-point argument with the sign of the
1.1048 + * second floating-point argument. Note that unlike the {@link
1.1049 + * StrictMath#copySign(float, float) StrictMath.copySign}
1.1050 + * method, this method does not require NaN {@code sign}
1.1051 + * arguments to be treated as positive values; implementations are
1.1052 + * permitted to treat some NaN arguments as positive and other NaN
1.1053 + * arguments as negative to allow greater performance.
1.1054 + *
1.1055 + * @param magnitude the parameter providing the magnitude of the result
1.1056 + * @param sign the parameter providing the sign of the result
1.1057 + * @return a value with the magnitude of {@code magnitude}
1.1058 + * and the sign of {@code sign}.
1.1059 + * @since 1.6
1.1060 + */
1.1061 +// public static float copySign(float magnitude, float sign) {
1.1062 +// return sun.misc.FpUtils.rawCopySign(magnitude, sign);
1.1063 +// }
1.1064 +
1.1065 + /**
1.1066 + * Returns the unbiased exponent used in the representation of a
1.1067 + * {@code float}. Special cases:
1.1068 + *
1.1069 + * <ul>
1.1070 + * <li>If the argument is NaN or infinite, then the result is
1.1071 + * {@link Float#MAX_EXPONENT} + 1.
1.1072 + * <li>If the argument is zero or subnormal, then the result is
1.1073 + * {@link Float#MIN_EXPONENT} -1.
1.1074 + * </ul>
1.1075 + * @param f a {@code float} value
1.1076 + * @return the unbiased exponent of the argument
1.1077 + * @since 1.6
1.1078 + */
1.1079 +// public static int getExponent(float f) {
1.1080 +// return sun.misc.FpUtils.getExponent(f);
1.1081 +// }
1.1082 +
1.1083 + /**
1.1084 + * Returns the unbiased exponent used in the representation of a
1.1085 + * {@code double}. Special cases:
1.1086 + *
1.1087 + * <ul>
1.1088 + * <li>If the argument is NaN or infinite, then the result is
1.1089 + * {@link Double#MAX_EXPONENT} + 1.
1.1090 + * <li>If the argument is zero or subnormal, then the result is
1.1091 + * {@link Double#MIN_EXPONENT} -1.
1.1092 + * </ul>
1.1093 + * @param d a {@code double} value
1.1094 + * @return the unbiased exponent of the argument
1.1095 + * @since 1.6
1.1096 + */
1.1097 +// public static int getExponent(double d) {
1.1098 +// return sun.misc.FpUtils.getExponent(d);
1.1099 +// }
1.1100 +
1.1101 + /**
1.1102 + * Returns the floating-point number adjacent to the first
1.1103 + * argument in the direction of the second argument. If both
1.1104 + * arguments compare as equal the second argument is returned.
1.1105 + *
1.1106 + * <p>
1.1107 + * Special cases:
1.1108 + * <ul>
1.1109 + * <li> If either argument is a NaN, then NaN is returned.
1.1110 + *
1.1111 + * <li> If both arguments are signed zeros, {@code direction}
1.1112 + * is returned unchanged (as implied by the requirement of
1.1113 + * returning the second argument if the arguments compare as
1.1114 + * equal).
1.1115 + *
1.1116 + * <li> If {@code start} is
1.1117 + * ±{@link Double#MIN_VALUE} and {@code direction}
1.1118 + * has a value such that the result should have a smaller
1.1119 + * magnitude, then a zero with the same sign as {@code start}
1.1120 + * is returned.
1.1121 + *
1.1122 + * <li> If {@code start} is infinite and
1.1123 + * {@code direction} has a value such that the result should
1.1124 + * have a smaller magnitude, {@link Double#MAX_VALUE} with the
1.1125 + * same sign as {@code start} is returned.
1.1126 + *
1.1127 + * <li> If {@code start} is equal to ±
1.1128 + * {@link Double#MAX_VALUE} and {@code direction} has a
1.1129 + * value such that the result should have a larger magnitude, an
1.1130 + * infinity with same sign as {@code start} is returned.
1.1131 + * </ul>
1.1132 + *
1.1133 + * @param start starting floating-point value
1.1134 + * @param direction value indicating which of
1.1135 + * {@code start}'s neighbors or {@code start} should
1.1136 + * be returned
1.1137 + * @return The floating-point number adjacent to {@code start} in the
1.1138 + * direction of {@code direction}.
1.1139 + * @since 1.6
1.1140 + */
1.1141 +// public static double nextAfter(double start, double direction) {
1.1142 +// return sun.misc.FpUtils.nextAfter(start, direction);
1.1143 +// }
1.1144 +
1.1145 + /**
1.1146 + * Returns the floating-point number adjacent to the first
1.1147 + * argument in the direction of the second argument. If both
1.1148 + * arguments compare as equal a value equivalent to the second argument
1.1149 + * is returned.
1.1150 + *
1.1151 + * <p>
1.1152 + * Special cases:
1.1153 + * <ul>
1.1154 + * <li> If either argument is a NaN, then NaN is returned.
1.1155 + *
1.1156 + * <li> If both arguments are signed zeros, a value equivalent
1.1157 + * to {@code direction} is returned.
1.1158 + *
1.1159 + * <li> If {@code start} is
1.1160 + * ±{@link Float#MIN_VALUE} and {@code direction}
1.1161 + * has a value such that the result should have a smaller
1.1162 + * magnitude, then a zero with the same sign as {@code start}
1.1163 + * is returned.
1.1164 + *
1.1165 + * <li> If {@code start} is infinite and
1.1166 + * {@code direction} has a value such that the result should
1.1167 + * have a smaller magnitude, {@link Float#MAX_VALUE} with the
1.1168 + * same sign as {@code start} is returned.
1.1169 + *
1.1170 + * <li> If {@code start} is equal to ±
1.1171 + * {@link Float#MAX_VALUE} and {@code direction} has a
1.1172 + * value such that the result should have a larger magnitude, an
1.1173 + * infinity with same sign as {@code start} is returned.
1.1174 + * </ul>
1.1175 + *
1.1176 + * @param start starting floating-point value
1.1177 + * @param direction value indicating which of
1.1178 + * {@code start}'s neighbors or {@code start} should
1.1179 + * be returned
1.1180 + * @return The floating-point number adjacent to {@code start} in the
1.1181 + * direction of {@code direction}.
1.1182 + * @since 1.6
1.1183 + */
1.1184 +// public static float nextAfter(float start, double direction) {
1.1185 +// return sun.misc.FpUtils.nextAfter(start, direction);
1.1186 +// }
1.1187 +
1.1188 + /**
1.1189 + * Returns the floating-point value adjacent to {@code d} in
1.1190 + * the direction of positive infinity. This method is
1.1191 + * semantically equivalent to {@code nextAfter(d,
1.1192 + * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
1.1193 + * implementation may run faster than its equivalent
1.1194 + * {@code nextAfter} call.
1.1195 + *
1.1196 + * <p>Special Cases:
1.1197 + * <ul>
1.1198 + * <li> If the argument is NaN, the result is NaN.
1.1199 + *
1.1200 + * <li> If the argument is positive infinity, the result is
1.1201 + * positive infinity.
1.1202 + *
1.1203 + * <li> If the argument is zero, the result is
1.1204 + * {@link Double#MIN_VALUE}
1.1205 + *
1.1206 + * </ul>
1.1207 + *
1.1208 + * @param d starting floating-point value
1.1209 + * @return The adjacent floating-point value closer to positive
1.1210 + * infinity.
1.1211 + * @since 1.6
1.1212 + */
1.1213 +// public static double nextUp(double d) {
1.1214 +// return sun.misc.FpUtils.nextUp(d);
1.1215 +// }
1.1216 +
1.1217 + /**
1.1218 + * Returns the floating-point value adjacent to {@code f} in
1.1219 + * the direction of positive infinity. This method is
1.1220 + * semantically equivalent to {@code nextAfter(f,
1.1221 + * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
1.1222 + * implementation may run faster than its equivalent
1.1223 + * {@code nextAfter} call.
1.1224 + *
1.1225 + * <p>Special Cases:
1.1226 + * <ul>
1.1227 + * <li> If the argument is NaN, the result is NaN.
1.1228 + *
1.1229 + * <li> If the argument is positive infinity, the result is
1.1230 + * positive infinity.
1.1231 + *
1.1232 + * <li> If the argument is zero, the result is
1.1233 + * {@link Float#MIN_VALUE}
1.1234 + *
1.1235 + * </ul>
1.1236 + *
1.1237 + * @param f starting floating-point value
1.1238 + * @return The adjacent floating-point value closer to positive
1.1239 + * infinity.
1.1240 + * @since 1.6
1.1241 + */
1.1242 +// public static float nextUp(float f) {
1.1243 +// return sun.misc.FpUtils.nextUp(f);
1.1244 +// }
1.1245 +
1.1246 +
1.1247 + /**
1.1248 + * Return {@code d} ×
1.1249 + * 2<sup>{@code scaleFactor}</sup> rounded as if performed
1.1250 + * by a single correctly rounded floating-point multiply to a
1.1251 + * member of the double value set. See the Java
1.1252 + * Language Specification for a discussion of floating-point
1.1253 + * value sets. If the exponent of the result is between {@link
1.1254 + * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
1.1255 + * answer is calculated exactly. If the exponent of the result
1.1256 + * would be larger than {@code Double.MAX_EXPONENT}, an
1.1257 + * infinity is returned. Note that if the result is subnormal,
1.1258 + * precision may be lost; that is, when {@code scalb(x, n)}
1.1259 + * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
1.1260 + * <i>x</i>. When the result is non-NaN, the result has the same
1.1261 + * sign as {@code d}.
1.1262 + *
1.1263 + * <p>Special cases:
1.1264 + * <ul>
1.1265 + * <li> If the first argument is NaN, NaN is returned.
1.1266 + * <li> If the first argument is infinite, then an infinity of the
1.1267 + * same sign is returned.
1.1268 + * <li> If the first argument is zero, then a zero of the same
1.1269 + * sign is returned.
1.1270 + * </ul>
1.1271 + *
1.1272 + * @param d number to be scaled by a power of two.
1.1273 + * @param scaleFactor power of 2 used to scale {@code d}
1.1274 + * @return {@code d} × 2<sup>{@code scaleFactor}</sup>
1.1275 + * @since 1.6
1.1276 + */
1.1277 +// public static double scalb(double d, int scaleFactor) {
1.1278 +// return sun.misc.FpUtils.scalb(d, scaleFactor);
1.1279 +// }
1.1280 +
1.1281 + /**
1.1282 + * Return {@code f} ×
1.1283 + * 2<sup>{@code scaleFactor}</sup> rounded as if performed
1.1284 + * by a single correctly rounded floating-point multiply to a
1.1285 + * member of the float value set. See the Java
1.1286 + * Language Specification for a discussion of floating-point
1.1287 + * value sets. If the exponent of the result is between {@link
1.1288 + * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
1.1289 + * answer is calculated exactly. If the exponent of the result
1.1290 + * would be larger than {@code Float.MAX_EXPONENT}, an
1.1291 + * infinity is returned. Note that if the result is subnormal,
1.1292 + * precision may be lost; that is, when {@code scalb(x, n)}
1.1293 + * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
1.1294 + * <i>x</i>. When the result is non-NaN, the result has the same
1.1295 + * sign as {@code f}.
1.1296 + *
1.1297 + * <p>Special cases:
1.1298 + * <ul>
1.1299 + * <li> If the first argument is NaN, NaN is returned.
1.1300 + * <li> If the first argument is infinite, then an infinity of the
1.1301 + * same sign is returned.
1.1302 + * <li> If the first argument is zero, then a zero of the same
1.1303 + * sign is returned.
1.1304 + * </ul>
1.1305 + *
1.1306 + * @param f number to be scaled by a power of two.
1.1307 + * @param scaleFactor power of 2 used to scale {@code f}
1.1308 + * @return {@code f} × 2<sup>{@code scaleFactor}</sup>
1.1309 + * @since 1.6
1.1310 + */
1.1311 +// public static float scalb(float f, int scaleFactor) {
1.1312 +// return sun.misc.FpUtils.scalb(f, scaleFactor);
1.1313 +// }
1.1314 +}