Adding also strict math jdk7-b147
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 29 Sep 2012 11:37:46 +0200
branchjdk7-b147
changeset 69e4d7540b796a
parent 68 a2924470187b
child 70 177ce4a56a6d
Adding also strict math
emul/src/main/java/java/lang/StrictMath.java
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/emul/src/main/java/java/lang/StrictMath.java	Sat Sep 29 11:37:46 2012 +0200
     1.3 @@ -0,0 +1,1468 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 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 +import java.util.Random;
    1.31 +import sun.misc.FpUtils;
    1.32 +import sun.misc.DoubleConsts;
    1.33 +
    1.34 +/**
    1.35 + * The class {@code StrictMath} 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>To help ensure portability of Java programs, the definitions of
    1.40 + * some of the numeric functions in this package require that they
    1.41 + * produce the same results as certain published algorithms. These
    1.42 + * algorithms are available from the well-known network library
    1.43 + * {@code netlib} as the package "Freely Distributable Math
    1.44 + * Library," <a
    1.45 + * href="ftp://ftp.netlib.org/fdlibm.tar">{@code fdlibm}</a>. These
    1.46 + * algorithms, which are written in the C programming language, are
    1.47 + * then to be understood as executed with all floating-point
    1.48 + * operations following the rules of Java floating-point arithmetic.
    1.49 + *
    1.50 + * <p>The Java math library is defined with respect to
    1.51 + * {@code fdlibm} version 5.3. Where {@code fdlibm} provides
    1.52 + * more than one definition for a function (such as
    1.53 + * {@code acos}), use the "IEEE 754 core function" version
    1.54 + * (residing in a file whose name begins with the letter
    1.55 + * {@code e}).  The methods which require {@code fdlibm}
    1.56 + * semantics are {@code sin}, {@code cos}, {@code tan},
    1.57 + * {@code asin}, {@code acos}, {@code atan},
    1.58 + * {@code exp}, {@code log}, {@code log10},
    1.59 + * {@code cbrt}, {@code atan2}, {@code pow},
    1.60 + * {@code sinh}, {@code cosh}, {@code tanh},
    1.61 + * {@code hypot}, {@code expm1}, and {@code log1p}.
    1.62 + *
    1.63 + * @author  unascribed
    1.64 + * @author  Joseph D. Darcy
    1.65 + * @since   1.3
    1.66 + */
    1.67 +
    1.68 +public final class StrictMath {
    1.69 +
    1.70 +    /**
    1.71 +     * Don't let anyone instantiate this class.
    1.72 +     */
    1.73 +    private StrictMath() {}
    1.74 +
    1.75 +    /**
    1.76 +     * The {@code double} value that is closer than any other to
    1.77 +     * <i>e</i>, the base of the natural logarithms.
    1.78 +     */
    1.79 +    public static final double E = 2.7182818284590452354;
    1.80 +
    1.81 +    /**
    1.82 +     * The {@code double} value that is closer than any other to
    1.83 +     * <i>pi</i>, the ratio of the circumference of a circle to its
    1.84 +     * diameter.
    1.85 +     */
    1.86 +    public static final double PI = 3.14159265358979323846;
    1.87 +
    1.88 +    /**
    1.89 +     * Returns the trigonometric sine of an angle. Special cases:
    1.90 +     * <ul><li>If the argument is NaN or an infinity, then the
    1.91 +     * result is NaN.
    1.92 +     * <li>If the argument is zero, then the result is a zero with the
    1.93 +     * same sign as the argument.</ul>
    1.94 +     *
    1.95 +     * @param   a   an angle, in radians.
    1.96 +     * @return  the sine of the argument.
    1.97 +     */
    1.98 +    public static native double sin(double a);
    1.99 +
   1.100 +    /**
   1.101 +     * Returns the trigonometric cosine of an angle. Special cases:
   1.102 +     * <ul><li>If the argument is NaN or an infinity, then the
   1.103 +     * result is NaN.</ul>
   1.104 +     *
   1.105 +     * @param   a   an angle, in radians.
   1.106 +     * @return  the cosine of the argument.
   1.107 +     */
   1.108 +    public static native double cos(double a);
   1.109 +
   1.110 +    /**
   1.111 +     * Returns the trigonometric tangent of an angle. Special cases:
   1.112 +     * <ul><li>If the argument is NaN or an infinity, then the result
   1.113 +     * is NaN.
   1.114 +     * <li>If the argument is zero, then the result is a zero with the
   1.115 +     * same sign as the argument.</ul>
   1.116 +     *
   1.117 +     * @param   a   an angle, in radians.
   1.118 +     * @return  the tangent of the argument.
   1.119 +     */
   1.120 +    public static native double tan(double a);
   1.121 +
   1.122 +    /**
   1.123 +     * Returns the arc sine of a value; the returned angle is in the
   1.124 +     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
   1.125 +     * <ul><li>If the argument is NaN or its absolute value is greater
   1.126 +     * than 1, then the result is NaN.
   1.127 +     * <li>If the argument is zero, then the result is a zero with the
   1.128 +     * same sign as the argument.</ul>
   1.129 +     *
   1.130 +     * @param   a   the value whose arc sine is to be returned.
   1.131 +     * @return  the arc sine of the argument.
   1.132 +     */
   1.133 +    public static native double asin(double a);
   1.134 +
   1.135 +    /**
   1.136 +     * Returns the arc cosine of a value; the returned angle is in the
   1.137 +     * range 0.0 through <i>pi</i>.  Special case:
   1.138 +     * <ul><li>If the argument is NaN or its absolute value is greater
   1.139 +     * than 1, then the result is NaN.</ul>
   1.140 +     *
   1.141 +     * @param   a   the value whose arc cosine is to be returned.
   1.142 +     * @return  the arc cosine of the argument.
   1.143 +     */
   1.144 +    public static native double acos(double a);
   1.145 +
   1.146 +    /**
   1.147 +     * Returns the arc tangent of a value; the returned angle is in the
   1.148 +     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
   1.149 +     * <ul><li>If the argument is NaN, then the result is NaN.
   1.150 +     * <li>If the argument is zero, then the result is a zero with the
   1.151 +     * same sign as the argument.</ul>
   1.152 +     *
   1.153 +     * @param   a   the value whose arc tangent is to be returned.
   1.154 +     * @return  the arc tangent of the argument.
   1.155 +     */
   1.156 +    public static native double atan(double a);
   1.157 +
   1.158 +    /**
   1.159 +     * Converts an angle measured in degrees to an approximately
   1.160 +     * equivalent angle measured in radians.  The conversion from
   1.161 +     * degrees to radians is generally inexact.
   1.162 +     *
   1.163 +     * @param   angdeg   an angle, in degrees
   1.164 +     * @return  the measurement of the angle {@code angdeg}
   1.165 +     *          in radians.
   1.166 +     */
   1.167 +    public static strictfp double toRadians(double angdeg) {
   1.168 +        return angdeg / 180.0 * PI;
   1.169 +    }
   1.170 +
   1.171 +    /**
   1.172 +     * Converts an angle measured in radians to an approximately
   1.173 +     * equivalent angle measured in degrees.  The conversion from
   1.174 +     * radians to degrees is generally inexact; users should
   1.175 +     * <i>not</i> expect {@code cos(toRadians(90.0))} to exactly
   1.176 +     * equal {@code 0.0}.
   1.177 +     *
   1.178 +     * @param   angrad   an angle, in radians
   1.179 +     * @return  the measurement of the angle {@code angrad}
   1.180 +     *          in degrees.
   1.181 +     */
   1.182 +    public static strictfp double toDegrees(double angrad) {
   1.183 +        return angrad * 180.0 / PI;
   1.184 +    }
   1.185 +
   1.186 +    /**
   1.187 +     * Returns Euler's number <i>e</i> raised to the power of a
   1.188 +     * {@code double} value. Special cases:
   1.189 +     * <ul><li>If the argument is NaN, the result is NaN.
   1.190 +     * <li>If the argument is positive infinity, then the result is
   1.191 +     * positive infinity.
   1.192 +     * <li>If the argument is negative infinity, then the result is
   1.193 +     * positive zero.</ul>
   1.194 +     *
   1.195 +     * @param   a   the exponent to raise <i>e</i> to.
   1.196 +     * @return  the value <i>e</i><sup>{@code a}</sup>,
   1.197 +     *          where <i>e</i> is the base of the natural logarithms.
   1.198 +     */
   1.199 +    public static native double exp(double a);
   1.200 +
   1.201 +    /**
   1.202 +     * Returns the natural logarithm (base <i>e</i>) of a {@code double}
   1.203 +     * value. Special cases:
   1.204 +     * <ul><li>If the argument is NaN or less than zero, then the result
   1.205 +     * is NaN.
   1.206 +     * <li>If the argument is positive infinity, then the result is
   1.207 +     * positive infinity.
   1.208 +     * <li>If the argument is positive zero or negative zero, then the
   1.209 +     * result is negative infinity.</ul>
   1.210 +     *
   1.211 +     * @param   a   a value
   1.212 +     * @return  the value ln&nbsp;{@code a}, the natural logarithm of
   1.213 +     *          {@code a}.
   1.214 +     */
   1.215 +    public static native double log(double a);
   1.216 +
   1.217 +
   1.218 +    /**
   1.219 +     * Returns the base 10 logarithm of a {@code double} value.
   1.220 +     * Special cases:
   1.221 +     *
   1.222 +     * <ul><li>If the argument is NaN or less than zero, then the result
   1.223 +     * is NaN.
   1.224 +     * <li>If the argument is positive infinity, then the result is
   1.225 +     * positive infinity.
   1.226 +     * <li>If the argument is positive zero or negative zero, then the
   1.227 +     * result is negative infinity.
   1.228 +     * <li> If the argument is equal to 10<sup><i>n</i></sup> for
   1.229 +     * integer <i>n</i>, then the result is <i>n</i>.
   1.230 +     * </ul>
   1.231 +     *
   1.232 +     * @param   a   a value
   1.233 +     * @return  the base 10 logarithm of  {@code a}.
   1.234 +     * @since 1.5
   1.235 +     */
   1.236 +    public static native double log10(double a);
   1.237 +
   1.238 +    /**
   1.239 +     * Returns the correctly rounded positive square root of a
   1.240 +     * {@code double} value.
   1.241 +     * Special cases:
   1.242 +     * <ul><li>If the argument is NaN or less than zero, then the result
   1.243 +     * is NaN.
   1.244 +     * <li>If the argument is positive infinity, then the result is positive
   1.245 +     * infinity.
   1.246 +     * <li>If the argument is positive zero or negative zero, then the
   1.247 +     * result is the same as the argument.</ul>
   1.248 +     * Otherwise, the result is the {@code double} value closest to
   1.249 +     * the true mathematical square root of the argument value.
   1.250 +     *
   1.251 +     * @param   a   a value.
   1.252 +     * @return  the positive square root of {@code a}.
   1.253 +     */
   1.254 +    public static native double sqrt(double a);
   1.255 +
   1.256 +    /**
   1.257 +     * Returns the cube root of a {@code double} value.  For
   1.258 +     * positive finite {@code x}, {@code cbrt(-x) ==
   1.259 +     * -cbrt(x)}; that is, the cube root of a negative value is
   1.260 +     * the negative of the cube root of that value's magnitude.
   1.261 +     * Special cases:
   1.262 +     *
   1.263 +     * <ul>
   1.264 +     *
   1.265 +     * <li>If the argument is NaN, then the result is NaN.
   1.266 +     *
   1.267 +     * <li>If the argument is infinite, then the result is an infinity
   1.268 +     * with the same sign as the argument.
   1.269 +     *
   1.270 +     * <li>If the argument is zero, then the result is a zero with the
   1.271 +     * same sign as the argument.
   1.272 +     *
   1.273 +     * </ul>
   1.274 +     *
   1.275 +     * @param   a   a value.
   1.276 +     * @return  the cube root of {@code a}.
   1.277 +     * @since 1.5
   1.278 +     */
   1.279 +    public static native double cbrt(double a);
   1.280 +
   1.281 +    /**
   1.282 +     * Computes the remainder operation on two arguments as prescribed
   1.283 +     * by the IEEE 754 standard.
   1.284 +     * The remainder value is mathematically equal to
   1.285 +     * <code>f1&nbsp;-&nbsp;f2</code>&nbsp;&times;&nbsp;<i>n</i>,
   1.286 +     * where <i>n</i> is the mathematical integer closest to the exact
   1.287 +     * mathematical value of the quotient {@code f1/f2}, and if two
   1.288 +     * mathematical integers are equally close to {@code f1/f2},
   1.289 +     * then <i>n</i> is the integer that is even. If the remainder is
   1.290 +     * zero, its sign is the same as the sign of the first argument.
   1.291 +     * Special cases:
   1.292 +     * <ul><li>If either argument is NaN, or the first argument is infinite,
   1.293 +     * or the second argument is positive zero or negative zero, then the
   1.294 +     * result is NaN.
   1.295 +     * <li>If the first argument is finite and the second argument is
   1.296 +     * infinite, then the result is the same as the first argument.</ul>
   1.297 +     *
   1.298 +     * @param   f1   the dividend.
   1.299 +     * @param   f2   the divisor.
   1.300 +     * @return  the remainder when {@code f1} is divided by
   1.301 +     *          {@code f2}.
   1.302 +     */
   1.303 +    public static native double IEEEremainder(double f1, double f2);
   1.304 +
   1.305 +    /**
   1.306 +     * Returns the smallest (closest to negative infinity)
   1.307 +     * {@code double} value that is greater than or equal to the
   1.308 +     * argument and is equal to a mathematical integer. Special cases:
   1.309 +     * <ul><li>If the argument value is already equal to a
   1.310 +     * mathematical integer, then the result is the same as the
   1.311 +     * argument.  <li>If the argument is NaN or an infinity or
   1.312 +     * positive zero or negative zero, then the result is the same as
   1.313 +     * the argument.  <li>If the argument value is less than zero but
   1.314 +     * greater than -1.0, then the result is negative zero.</ul> Note
   1.315 +     * that the value of {@code StrictMath.ceil(x)} is exactly the
   1.316 +     * value of {@code -StrictMath.floor(-x)}.
   1.317 +     *
   1.318 +     * @param   a   a value.
   1.319 +     * @return  the smallest (closest to negative infinity)
   1.320 +     *          floating-point value that is greater than or equal to
   1.321 +     *          the argument and is equal to a mathematical integer.
   1.322 +     */
   1.323 +    public static double ceil(double a) {
   1.324 +        return floorOrCeil(a, -0.0, 1.0, 1.0);
   1.325 +    }
   1.326 +
   1.327 +    /**
   1.328 +     * Returns the largest (closest to positive infinity)
   1.329 +     * {@code double} value that is less than or equal to the
   1.330 +     * argument and is equal to a mathematical integer. Special cases:
   1.331 +     * <ul><li>If the argument value is already equal to a
   1.332 +     * mathematical integer, then the result is the same as the
   1.333 +     * argument.  <li>If the argument is NaN or an infinity or
   1.334 +     * positive zero or negative zero, then the result is the same as
   1.335 +     * the argument.</ul>
   1.336 +     *
   1.337 +     * @param   a   a value.
   1.338 +     * @return  the largest (closest to positive infinity)
   1.339 +     *          floating-point value that less than or equal to the argument
   1.340 +     *          and is equal to a mathematical integer.
   1.341 +     */
   1.342 +    public static double floor(double a) {
   1.343 +        return floorOrCeil(a, -1.0, 0.0, -1.0);
   1.344 +    }
   1.345 +
   1.346 +    /**
   1.347 +     * Internal method to share logic between floor and ceil.
   1.348 +     *
   1.349 +     * @param a the value to be floored or ceiled
   1.350 +     * @param negativeBoundary result for values in (-1, 0)
   1.351 +     * @param positiveBoundary result for values in (0, 1)
   1.352 +     * @param increment value to add when the argument is non-integral
   1.353 +     */
   1.354 +    private static double floorOrCeil(double a,
   1.355 +                                      double negativeBoundary,
   1.356 +                                      double positiveBoundary,
   1.357 +                                      double sign) {
   1.358 +        int exponent = Math.getExponent(a);
   1.359 +
   1.360 +        if (exponent < 0) {
   1.361 +            /*
   1.362 +             * Absolute value of argument is less than 1.
   1.363 +             * floorOrceil(-0.0) => -0.0
   1.364 +             * floorOrceil(+0.0) => +0.0
   1.365 +             */
   1.366 +            return ((a == 0.0) ? a :
   1.367 +                    ( (a < 0.0) ?  negativeBoundary : positiveBoundary) );
   1.368 +        } else if (exponent >= 52) {
   1.369 +            /*
   1.370 +             * Infinity, NaN, or a value so large it must be integral.
   1.371 +             */
   1.372 +            return a;
   1.373 +        }
   1.374 +        // Else the argument is either an integral value already XOR it
   1.375 +        // has to be rounded to one.
   1.376 +        assert exponent >= 0 && exponent <= 51;
   1.377 +
   1.378 +        long doppel = Double.doubleToRawLongBits(a);
   1.379 +        long mask   = DoubleConsts.SIGNIF_BIT_MASK >> exponent;
   1.380 +
   1.381 +        if ( (mask & doppel) == 0L )
   1.382 +            return a; // integral value
   1.383 +        else {
   1.384 +            double result = Double.longBitsToDouble(doppel & (~mask));
   1.385 +            if (sign*a > 0.0)
   1.386 +                result = result + sign;
   1.387 +            return result;
   1.388 +        }
   1.389 +    }
   1.390 +
   1.391 +    /**
   1.392 +     * Returns the {@code double} value that is closest in value
   1.393 +     * to the argument and is equal to a mathematical integer. If two
   1.394 +     * {@code double} values that are mathematical integers are
   1.395 +     * equally close to the value of the argument, the result is the
   1.396 +     * integer value that is even. Special cases:
   1.397 +     * <ul><li>If the argument value is already equal to a mathematical
   1.398 +     * integer, then the result is the same as the argument.
   1.399 +     * <li>If the argument is NaN or an infinity or positive zero or negative
   1.400 +     * zero, then the result is the same as the argument.</ul>
   1.401 +     *
   1.402 +     * @param   a   a value.
   1.403 +     * @return  the closest floating-point value to {@code a} that is
   1.404 +     *          equal to a mathematical integer.
   1.405 +     * @author Joseph D. Darcy
   1.406 +     */
   1.407 +    public static double rint(double a) {
   1.408 +        /*
   1.409 +         * If the absolute value of a is not less than 2^52, it
   1.410 +         * is either a finite integer (the double format does not have
   1.411 +         * enough significand bits for a number that large to have any
   1.412 +         * fractional portion), an infinity, or a NaN.  In any of
   1.413 +         * these cases, rint of the argument is the argument.
   1.414 +         *
   1.415 +         * Otherwise, the sum (twoToThe52 + a ) will properly round
   1.416 +         * away any fractional portion of a since ulp(twoToThe52) ==
   1.417 +         * 1.0; subtracting out twoToThe52 from this sum will then be
   1.418 +         * exact and leave the rounded integer portion of a.
   1.419 +         *
   1.420 +         * This method does *not* need to be declared strictfp to get
   1.421 +         * fully reproducible results.  Whether or not a method is
   1.422 +         * declared strictfp can only make a difference in the
   1.423 +         * returned result if some operation would overflow or
   1.424 +         * underflow with strictfp semantics.  The operation
   1.425 +         * (twoToThe52 + a ) cannot overflow since large values of a
   1.426 +         * are screened out; the add cannot underflow since twoToThe52
   1.427 +         * is too large.  The subtraction ((twoToThe52 + a ) -
   1.428 +         * twoToThe52) will be exact as discussed above and thus
   1.429 +         * cannot overflow or meaningfully underflow.  Finally, the
   1.430 +         * last multiply in the return statement is by plus or minus
   1.431 +         * 1.0, which is exact too.
   1.432 +         */
   1.433 +        double twoToThe52 = (double)(1L << 52); // 2^52
   1.434 +        double sign = FpUtils.rawCopySign(1.0, a); // preserve sign info
   1.435 +        a = Math.abs(a);
   1.436 +
   1.437 +        if (a < twoToThe52) { // E_min <= ilogb(a) <= 51
   1.438 +            a = ((twoToThe52 + a ) - twoToThe52);
   1.439 +        }
   1.440 +
   1.441 +        return sign * a; // restore original sign
   1.442 +    }
   1.443 +
   1.444 +    /**
   1.445 +     * Returns the angle <i>theta</i> from the conversion of rectangular
   1.446 +     * coordinates ({@code x},&nbsp;{@code y}) to polar
   1.447 +     * coordinates (r,&nbsp;<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 +     * @param   y   the ordinate coordinate
   1.487 +     * @param   x   the abscissa coordinate
   1.488 +     * @return  the <i>theta</i> component of the point
   1.489 +     *          (<i>r</i>,&nbsp;<i>theta</i>)
   1.490 +     *          in polar coordinates that corresponds to the point
   1.491 +     *          (<i>x</i>,&nbsp;<i>y</i>) in Cartesian coordinates.
   1.492 +     */
   1.493 +    public static native double atan2(double y, double x);
   1.494 +
   1.495 +
   1.496 +    /**
   1.497 +     * Returns the value of the first argument raised to the power of the
   1.498 +     * second argument. Special cases:
   1.499 +     *
   1.500 +     * <ul><li>If the second argument is positive or negative zero, then the
   1.501 +     * result is 1.0.
   1.502 +     * <li>If the second argument is 1.0, then the result is the same as the
   1.503 +     * first argument.
   1.504 +     * <li>If the second argument is NaN, then the result is NaN.
   1.505 +     * <li>If the first argument is NaN and the second argument is nonzero,
   1.506 +     * then the result is NaN.
   1.507 +     *
   1.508 +     * <li>If
   1.509 +     * <ul>
   1.510 +     * <li>the absolute value of the first argument is greater than 1
   1.511 +     * and the second argument is positive infinity, or
   1.512 +     * <li>the absolute value of the first argument is less than 1 and
   1.513 +     * the second argument is negative infinity,
   1.514 +     * </ul>
   1.515 +     * then the result is positive infinity.
   1.516 +     *
   1.517 +     * <li>If
   1.518 +     * <ul>
   1.519 +     * <li>the absolute value of the first argument is greater than 1 and
   1.520 +     * the second argument is negative infinity, or
   1.521 +     * <li>the absolute value of the
   1.522 +     * first argument is less than 1 and the second argument is positive
   1.523 +     * infinity,
   1.524 +     * </ul>
   1.525 +     * then the result is positive zero.
   1.526 +     *
   1.527 +     * <li>If the absolute value of the first argument equals 1 and the
   1.528 +     * second argument is infinite, then the result is NaN.
   1.529 +     *
   1.530 +     * <li>If
   1.531 +     * <ul>
   1.532 +     * <li>the first argument is positive zero and the second argument
   1.533 +     * is greater than zero, or
   1.534 +     * <li>the first argument is positive infinity and the second
   1.535 +     * argument is less than zero,
   1.536 +     * </ul>
   1.537 +     * then the result is positive zero.
   1.538 +     *
   1.539 +     * <li>If
   1.540 +     * <ul>
   1.541 +     * <li>the first argument is positive zero and the second argument
   1.542 +     * is less than zero, or
   1.543 +     * <li>the first argument is positive infinity and the second
   1.544 +     * argument is greater than zero,
   1.545 +     * </ul>
   1.546 +     * then the result is positive infinity.
   1.547 +     *
   1.548 +     * <li>If
   1.549 +     * <ul>
   1.550 +     * <li>the first argument is negative zero and the second argument
   1.551 +     * is greater than zero but not a finite odd integer, or
   1.552 +     * <li>the first argument is negative infinity and the second
   1.553 +     * argument is less than zero but not a finite odd integer,
   1.554 +     * </ul>
   1.555 +     * then the result is positive zero.
   1.556 +     *
   1.557 +     * <li>If
   1.558 +     * <ul>
   1.559 +     * <li>the first argument is negative zero and the second argument
   1.560 +     * is a positive finite odd integer, or
   1.561 +     * <li>the first argument is negative infinity and the second
   1.562 +     * argument is a negative finite odd integer,
   1.563 +     * </ul>
   1.564 +     * then the result is negative zero.
   1.565 +     *
   1.566 +     * <li>If
   1.567 +     * <ul>
   1.568 +     * <li>the first argument is negative zero and the second argument
   1.569 +     * is less than zero but not a finite odd integer, or
   1.570 +     * <li>the first argument is negative infinity and the second
   1.571 +     * argument is greater than zero but not a finite odd integer,
   1.572 +     * </ul>
   1.573 +     * then the result is positive infinity.
   1.574 +     *
   1.575 +     * <li>If
   1.576 +     * <ul>
   1.577 +     * <li>the first argument is negative zero and the second argument
   1.578 +     * is a negative finite odd integer, or
   1.579 +     * <li>the first argument is negative infinity and the second
   1.580 +     * argument is a positive finite odd integer,
   1.581 +     * </ul>
   1.582 +     * then the result is negative infinity.
   1.583 +     *
   1.584 +     * <li>If the first argument is finite and less than zero
   1.585 +     * <ul>
   1.586 +     * <li> if the second argument is a finite even integer, the
   1.587 +     * result is equal to the result of raising the absolute value of
   1.588 +     * the first argument to the power of the second argument
   1.589 +     *
   1.590 +     * <li>if the second argument is a finite odd integer, the result
   1.591 +     * is equal to the negative of the result of raising the absolute
   1.592 +     * value of the first argument to the power of the second
   1.593 +     * argument
   1.594 +     *
   1.595 +     * <li>if the second argument is finite and not an integer, then
   1.596 +     * the result is NaN.
   1.597 +     * </ul>
   1.598 +     *
   1.599 +     * <li>If both arguments are integers, then the result is exactly equal
   1.600 +     * to the mathematical result of raising the first argument to the power
   1.601 +     * of the second argument if that result can in fact be represented
   1.602 +     * exactly as a {@code double} value.</ul>
   1.603 +     *
   1.604 +     * <p>(In the foregoing descriptions, a floating-point value is
   1.605 +     * considered to be an integer if and only if it is finite and a
   1.606 +     * fixed point of the method {@link #ceil ceil} or,
   1.607 +     * equivalently, a fixed point of the method {@link #floor
   1.608 +     * floor}. A value is a fixed point of a one-argument
   1.609 +     * method if and only if the result of applying the method to the
   1.610 +     * value is equal to the value.)
   1.611 +     *
   1.612 +     * @param   a   base.
   1.613 +     * @param   b   the exponent.
   1.614 +     * @return  the value {@code a}<sup>{@code b}</sup>.
   1.615 +     */
   1.616 +    public static native double pow(double a, double b);
   1.617 +
   1.618 +    /**
   1.619 +     * Returns the closest {@code int} to the argument, with ties
   1.620 +     * rounding up.
   1.621 +     *
   1.622 +     * <p>Special cases:
   1.623 +     * <ul><li>If the argument is NaN, the result is 0.
   1.624 +     * <li>If the argument is negative infinity or any value less than or
   1.625 +     * equal to the value of {@code Integer.MIN_VALUE}, the result is
   1.626 +     * equal to the value of {@code Integer.MIN_VALUE}.
   1.627 +     * <li>If the argument is positive infinity or any value greater than or
   1.628 +     * equal to the value of {@code Integer.MAX_VALUE}, the result is
   1.629 +     * equal to the value of {@code Integer.MAX_VALUE}.</ul>
   1.630 +     *
   1.631 +     * @param   a   a floating-point value to be rounded to an integer.
   1.632 +     * @return  the value of the argument rounded to the nearest
   1.633 +     *          {@code int} value.
   1.634 +     * @see     java.lang.Integer#MAX_VALUE
   1.635 +     * @see     java.lang.Integer#MIN_VALUE
   1.636 +     */
   1.637 +    public static int round(float a) {
   1.638 +        return Math.round(a);
   1.639 +    }
   1.640 +
   1.641 +    /**
   1.642 +     * Returns the closest {@code long} to the argument, with ties
   1.643 +     * rounding up.
   1.644 +     *
   1.645 +     * <p>Special cases:
   1.646 +     * <ul><li>If the argument is NaN, the result is 0.
   1.647 +     * <li>If the argument is negative infinity or any value less than or
   1.648 +     * equal to the value of {@code Long.MIN_VALUE}, the result is
   1.649 +     * equal to the value of {@code Long.MIN_VALUE}.
   1.650 +     * <li>If the argument is positive infinity or any value greater than or
   1.651 +     * equal to the value of {@code Long.MAX_VALUE}, the result is
   1.652 +     * equal to the value of {@code Long.MAX_VALUE}.</ul>
   1.653 +     *
   1.654 +     * @param   a  a floating-point value to be rounded to a
   1.655 +     *          {@code long}.
   1.656 +     * @return  the value of the argument rounded to the nearest
   1.657 +     *          {@code long} value.
   1.658 +     * @see     java.lang.Long#MAX_VALUE
   1.659 +     * @see     java.lang.Long#MIN_VALUE
   1.660 +     */
   1.661 +    public static long round(double a) {
   1.662 +        return Math.round(a);
   1.663 +    }
   1.664 +
   1.665 +    private static Random randomNumberGenerator;
   1.666 +
   1.667 +    private static synchronized Random initRNG() {
   1.668 +        Random rnd = randomNumberGenerator;
   1.669 +        return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd;
   1.670 +    }
   1.671 +
   1.672 +    /**
   1.673 +     * Returns a {@code double} value with a positive sign, greater
   1.674 +     * than or equal to {@code 0.0} and less than {@code 1.0}.
   1.675 +     * Returned values are chosen pseudorandomly with (approximately)
   1.676 +     * uniform distribution from that range.
   1.677 +     *
   1.678 +     * <p>When this method is first called, it creates a single new
   1.679 +     * pseudorandom-number generator, exactly as if by the expression
   1.680 +     *
   1.681 +     * <blockquote>{@code new java.util.Random()}</blockquote>
   1.682 +     *
   1.683 +     * This new pseudorandom-number generator is used thereafter for
   1.684 +     * all calls to this method and is used nowhere else.
   1.685 +     *
   1.686 +     * <p>This method is properly synchronized to allow correct use by
   1.687 +     * more than one thread. However, if many threads need to generate
   1.688 +     * pseudorandom numbers at a great rate, it may reduce contention
   1.689 +     * for each thread to have its own pseudorandom number generator.
   1.690 +     *
   1.691 +     * @return  a pseudorandom {@code double} greater than or equal
   1.692 +     * to {@code 0.0} and less than {@code 1.0}.
   1.693 +     * @see Random#nextDouble()
   1.694 +     */
   1.695 +    public static double random() {
   1.696 +        Random rnd = randomNumberGenerator;
   1.697 +        if (rnd == null) rnd = initRNG();
   1.698 +        return rnd.nextDouble();
   1.699 +    }
   1.700 +
   1.701 +    /**
   1.702 +     * Returns the absolute value of an {@code int} value..
   1.703 +     * If the argument is not negative, the argument is returned.
   1.704 +     * If the argument is negative, the negation of the argument is returned.
   1.705 +     *
   1.706 +     * <p>Note that if the argument is equal to the value of
   1.707 +     * {@link Integer#MIN_VALUE}, the most negative representable
   1.708 +     * {@code int} value, the result is that same value, which is
   1.709 +     * negative.
   1.710 +     *
   1.711 +     * @param   a   the  argument whose absolute value is to be determined.
   1.712 +     * @return  the absolute value of the argument.
   1.713 +     */
   1.714 +    public static int abs(int a) {
   1.715 +        return (a < 0) ? -a : a;
   1.716 +    }
   1.717 +
   1.718 +    /**
   1.719 +     * Returns the absolute value of a {@code long} value.
   1.720 +     * If the argument is not negative, the argument is returned.
   1.721 +     * If the argument is negative, the negation of the argument is returned.
   1.722 +     *
   1.723 +     * <p>Note that if the argument is equal to the value of
   1.724 +     * {@link Long#MIN_VALUE}, the most negative representable
   1.725 +     * {@code long} value, the result is that same value, which
   1.726 +     * is negative.
   1.727 +     *
   1.728 +     * @param   a   the  argument whose absolute value is to be determined.
   1.729 +     * @return  the absolute value of the argument.
   1.730 +     */
   1.731 +    public static long abs(long a) {
   1.732 +        return (a < 0) ? -a : a;
   1.733 +    }
   1.734 +
   1.735 +    /**
   1.736 +     * Returns the absolute value of a {@code float} value.
   1.737 +     * If the argument is not negative, the argument is returned.
   1.738 +     * If the argument is negative, the negation of the argument is returned.
   1.739 +     * Special cases:
   1.740 +     * <ul><li>If the argument is positive zero or negative zero, the
   1.741 +     * result is positive zero.
   1.742 +     * <li>If the argument is infinite, the result is positive infinity.
   1.743 +     * <li>If the argument is NaN, the result is NaN.</ul>
   1.744 +     * In other words, the result is the same as the value of the expression:
   1.745 +     * <p>{@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
   1.746 +     *
   1.747 +     * @param   a   the argument whose absolute value is to be determined
   1.748 +     * @return  the absolute value of the argument.
   1.749 +     */
   1.750 +    public static float abs(float a) {
   1.751 +        return (a <= 0.0F) ? 0.0F - a : a;
   1.752 +    }
   1.753 +
   1.754 +    /**
   1.755 +     * Returns the absolute value of a {@code double} value.
   1.756 +     * If the argument is not negative, the argument is returned.
   1.757 +     * If the argument is negative, the negation of the argument is returned.
   1.758 +     * Special cases:
   1.759 +     * <ul><li>If the argument is positive zero or negative zero, the result
   1.760 +     * is positive zero.
   1.761 +     * <li>If the argument is infinite, the result is positive infinity.
   1.762 +     * <li>If the argument is NaN, the result is NaN.</ul>
   1.763 +     * In other words, the result is the same as the value of the expression:
   1.764 +     * <p>{@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
   1.765 +     *
   1.766 +     * @param   a   the argument whose absolute value is to be determined
   1.767 +     * @return  the absolute value of the argument.
   1.768 +     */
   1.769 +    public static double abs(double a) {
   1.770 +        return (a <= 0.0D) ? 0.0D - a : a;
   1.771 +    }
   1.772 +
   1.773 +    /**
   1.774 +     * Returns the greater of two {@code int} values. That is, the
   1.775 +     * result is the argument closer to the value of
   1.776 +     * {@link Integer#MAX_VALUE}. If the arguments have the same value,
   1.777 +     * the result is that same value.
   1.778 +     *
   1.779 +     * @param   a   an argument.
   1.780 +     * @param   b   another argument.
   1.781 +     * @return  the larger of {@code a} and {@code b}.
   1.782 +     */
   1.783 +    public static int max(int a, int b) {
   1.784 +        return (a >= b) ? a : b;
   1.785 +    }
   1.786 +
   1.787 +    /**
   1.788 +     * Returns the greater of two {@code long} values. That is, the
   1.789 +     * result is the argument closer to the value of
   1.790 +     * {@link Long#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 long max(long a, long b) {
   1.798 +        return (a >= b) ? a : b;
   1.799 +    }
   1.800 +
   1.801 +    // Use raw bit-wise conversions on guaranteed non-NaN arguments.
   1.802 +    private static long negativeZeroFloatBits  = Float.floatToRawIntBits(-0.0f);
   1.803 +    private static long negativeZeroDoubleBits = Double.doubleToRawLongBits(-0.0d);
   1.804 +
   1.805 +    /**
   1.806 +     * Returns the greater of two {@code float} values.  That is,
   1.807 +     * the result is the argument closer to positive infinity. If the
   1.808 +     * arguments have the same value, the result is that same
   1.809 +     * value. If either value is NaN, then the result is NaN.  Unlike
   1.810 +     * the numerical comparison operators, this method considers
   1.811 +     * negative zero to be strictly smaller than positive zero. If one
   1.812 +     * argument is positive zero and the other negative zero, the
   1.813 +     * result is positive zero.
   1.814 +     *
   1.815 +     * @param   a   an argument.
   1.816 +     * @param   b   another argument.
   1.817 +     * @return  the larger of {@code a} and {@code b}.
   1.818 +     */
   1.819 +    public static float max(float a, float b) {
   1.820 +        if (a != a)
   1.821 +            return a;   // a is NaN
   1.822 +        if ((a == 0.0f) &&
   1.823 +            (b == 0.0f) &&
   1.824 +            (Float.floatToRawIntBits(a) == negativeZeroFloatBits)) {
   1.825 +            // Raw conversion ok since NaN can't map to -0.0.
   1.826 +            return b;
   1.827 +        }
   1.828 +        return (a >= b) ? a : b;
   1.829 +    }
   1.830 +
   1.831 +    /**
   1.832 +     * Returns the greater of two {@code double} values.  That
   1.833 +     * is, the result is the argument closer to positive infinity. If
   1.834 +     * the arguments have the same value, the result is that same
   1.835 +     * value. If either value is NaN, then the result is NaN.  Unlike
   1.836 +     * the numerical comparison operators, this method considers
   1.837 +     * negative zero to be strictly smaller than positive zero. If one
   1.838 +     * argument is positive zero and the other negative zero, the
   1.839 +     * result is positive zero.
   1.840 +     *
   1.841 +     * @param   a   an argument.
   1.842 +     * @param   b   another argument.
   1.843 +     * @return  the larger of {@code a} and {@code b}.
   1.844 +     */
   1.845 +    public static double max(double a, double b) {
   1.846 +        if (a != a)
   1.847 +            return a;   // a is NaN
   1.848 +        if ((a == 0.0d) &&
   1.849 +            (b == 0.0d) &&
   1.850 +            (Double.doubleToRawLongBits(a) == negativeZeroDoubleBits)) {
   1.851 +            // Raw conversion ok since NaN can't map to -0.0.
   1.852 +            return b;
   1.853 +        }
   1.854 +        return (a >= b) ? a : b;
   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 +    public static float min(float a, float b) {
   1.900 +        if (a != a)
   1.901 +            return a;   // a is NaN
   1.902 +        if ((a == 0.0f) &&
   1.903 +            (b == 0.0f) &&
   1.904 +            (Float.floatToRawIntBits(b) == negativeZeroFloatBits)) {
   1.905 +            // Raw conversion ok since NaN can't map to -0.0.
   1.906 +            return b;
   1.907 +        }
   1.908 +        return (a <= b) ? a : b;
   1.909 +    }
   1.910 +
   1.911 +    /**
   1.912 +     * Returns the smaller of two {@code double} values.  That
   1.913 +     * is, the result is the value closer to negative infinity. If the
   1.914 +     * arguments have the same value, the result is that same
   1.915 +     * value. If either value is NaN, then the result is NaN.  Unlike
   1.916 +     * the numerical comparison operators, this method considers
   1.917 +     * negative zero to be strictly smaller than positive zero. If one
   1.918 +     * argument is positive zero and the other is negative zero, the
   1.919 +     * result is negative zero.
   1.920 +     *
   1.921 +     * @param   a   an argument.
   1.922 +     * @param   b   another argument.
   1.923 +     * @return  the smaller of {@code a} and {@code b}.
   1.924 +     */
   1.925 +    public static double min(double a, double b) {
   1.926 +        if (a != a)
   1.927 +            return a;   // a is NaN
   1.928 +        if ((a == 0.0d) &&
   1.929 +            (b == 0.0d) &&
   1.930 +            (Double.doubleToRawLongBits(b) == negativeZeroDoubleBits)) {
   1.931 +            // Raw conversion ok since NaN can't map to -0.0.
   1.932 +            return b;
   1.933 +        }
   1.934 +        return (a <= b) ? a : b;
   1.935 +    }
   1.936 +
   1.937 +    /**
   1.938 +     * Returns the size of an ulp of the argument.  An ulp of a
   1.939 +     * {@code double} value is the positive distance between this
   1.940 +     * floating-point value and the {@code double} value next
   1.941 +     * larger in magnitude.  Note that for non-NaN <i>x</i>,
   1.942 +     * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
   1.943 +     *
   1.944 +     * <p>Special Cases:
   1.945 +     * <ul>
   1.946 +     * <li> If the argument is NaN, then the result is NaN.
   1.947 +     * <li> If the argument is positive or negative infinity, then the
   1.948 +     * result is positive infinity.
   1.949 +     * <li> If the argument is positive or negative zero, then the result is
   1.950 +     * {@code Double.MIN_VALUE}.
   1.951 +     * <li> If the argument is &plusmn;{@code Double.MAX_VALUE}, then
   1.952 +     * the result is equal to 2<sup>971</sup>.
   1.953 +     * </ul>
   1.954 +     *
   1.955 +     * @param d the floating-point value whose ulp is to be returned
   1.956 +     * @return the size of an ulp of the argument
   1.957 +     * @author Joseph D. Darcy
   1.958 +     * @since 1.5
   1.959 +     */
   1.960 +    public static double ulp(double d) {
   1.961 +        return sun.misc.FpUtils.ulp(d);
   1.962 +    }
   1.963 +
   1.964 +    /**
   1.965 +     * Returns the size of an ulp of the argument.  An ulp of a
   1.966 +     * {@code float} value is the positive distance between this
   1.967 +     * floating-point value and the {@code float} value next
   1.968 +     * larger in magnitude.  Note that for non-NaN <i>x</i>,
   1.969 +     * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
   1.970 +     *
   1.971 +     * <p>Special Cases:
   1.972 +     * <ul>
   1.973 +     * <li> If the argument is NaN, then the result is NaN.
   1.974 +     * <li> If the argument is positive or negative infinity, then the
   1.975 +     * result is positive infinity.
   1.976 +     * <li> If the argument is positive or negative zero, then the result is
   1.977 +     * {@code Float.MIN_VALUE}.
   1.978 +     * <li> If the argument is &plusmn;{@code Float.MAX_VALUE}, then
   1.979 +     * the result is equal to 2<sup>104</sup>.
   1.980 +     * </ul>
   1.981 +     *
   1.982 +     * @param f the floating-point value whose ulp is to be returned
   1.983 +     * @return the size of an ulp of the argument
   1.984 +     * @author Joseph D. Darcy
   1.985 +     * @since 1.5
   1.986 +     */
   1.987 +    public static float ulp(float f) {
   1.988 +        return sun.misc.FpUtils.ulp(f);
   1.989 +    }
   1.990 +
   1.991 +    /**
   1.992 +     * Returns the signum function of the argument; zero if the argument
   1.993 +     * is zero, 1.0 if the argument is greater than zero, -1.0 if the
   1.994 +     * argument is less than zero.
   1.995 +     *
   1.996 +     * <p>Special Cases:
   1.997 +     * <ul>
   1.998 +     * <li> If the argument is NaN, then the result is NaN.
   1.999 +     * <li> If the argument is positive zero or negative zero, then the
  1.1000 +     *      result is the same as the argument.
  1.1001 +     * </ul>
  1.1002 +     *
  1.1003 +     * @param d the floating-point value whose signum is to be returned
  1.1004 +     * @return the signum function of the argument
  1.1005 +     * @author Joseph D. Darcy
  1.1006 +     * @since 1.5
  1.1007 +     */
  1.1008 +    public static double signum(double d) {
  1.1009 +        return sun.misc.FpUtils.signum(d);
  1.1010 +    }
  1.1011 +
  1.1012 +    /**
  1.1013 +     * Returns the signum function of the argument; zero if the argument
  1.1014 +     * is zero, 1.0f if the argument is greater than zero, -1.0f if the
  1.1015 +     * argument is less than zero.
  1.1016 +     *
  1.1017 +     * <p>Special Cases:
  1.1018 +     * <ul>
  1.1019 +     * <li> If the argument is NaN, then the result is NaN.
  1.1020 +     * <li> If the argument is positive zero or negative zero, then the
  1.1021 +     *      result is the same as the argument.
  1.1022 +     * </ul>
  1.1023 +     *
  1.1024 +     * @param f the floating-point value whose signum is to be returned
  1.1025 +     * @return the signum function of the argument
  1.1026 +     * @author Joseph D. Darcy
  1.1027 +     * @since 1.5
  1.1028 +     */
  1.1029 +    public static float signum(float f) {
  1.1030 +        return sun.misc.FpUtils.signum(f);
  1.1031 +    }
  1.1032 +
  1.1033 +    /**
  1.1034 +     * Returns the hyperbolic sine of a {@code double} value.
  1.1035 +     * The hyperbolic sine of <i>x</i> is defined to be
  1.1036 +     * (<i>e<sup>x</sup>&nbsp;-&nbsp;e<sup>-x</sup></i>)/2
  1.1037 +     * where <i>e</i> is {@linkplain Math#E Euler's number}.
  1.1038 +     *
  1.1039 +     * <p>Special cases:
  1.1040 +     * <ul>
  1.1041 +     *
  1.1042 +     * <li>If the argument is NaN, then the result is NaN.
  1.1043 +     *
  1.1044 +     * <li>If the argument is infinite, then the result is an infinity
  1.1045 +     * with the same sign as the argument.
  1.1046 +     *
  1.1047 +     * <li>If the argument is zero, then the result is a zero with the
  1.1048 +     * same sign as the argument.
  1.1049 +     *
  1.1050 +     * </ul>
  1.1051 +     *
  1.1052 +     * @param   x The number whose hyperbolic sine is to be returned.
  1.1053 +     * @return  The hyperbolic sine of {@code x}.
  1.1054 +     * @since 1.5
  1.1055 +     */
  1.1056 +    public static native double sinh(double x);
  1.1057 +
  1.1058 +    /**
  1.1059 +     * Returns the hyperbolic cosine of a {@code double} value.
  1.1060 +     * The hyperbolic cosine of <i>x</i> is defined to be
  1.1061 +     * (<i>e<sup>x</sup>&nbsp;+&nbsp;e<sup>-x</sup></i>)/2
  1.1062 +     * where <i>e</i> is {@linkplain Math#E Euler's number}.
  1.1063 +     *
  1.1064 +     * <p>Special cases:
  1.1065 +     * <ul>
  1.1066 +     *
  1.1067 +     * <li>If the argument is NaN, then the result is NaN.
  1.1068 +     *
  1.1069 +     * <li>If the argument is infinite, then the result is positive
  1.1070 +     * infinity.
  1.1071 +     *
  1.1072 +     * <li>If the argument is zero, then the result is {@code 1.0}.
  1.1073 +     *
  1.1074 +     * </ul>
  1.1075 +     *
  1.1076 +     * @param   x The number whose hyperbolic cosine is to be returned.
  1.1077 +     * @return  The hyperbolic cosine of {@code x}.
  1.1078 +     * @since 1.5
  1.1079 +     */
  1.1080 +    public static native double cosh(double x);
  1.1081 +
  1.1082 +    /**
  1.1083 +     * Returns the hyperbolic tangent of a {@code double} value.
  1.1084 +     * The hyperbolic tangent of <i>x</i> is defined to be
  1.1085 +     * (<i>e<sup>x</sup>&nbsp;-&nbsp;e<sup>-x</sup></i>)/(<i>e<sup>x</sup>&nbsp;+&nbsp;e<sup>-x</sup></i>),
  1.1086 +     * in other words, {@linkplain Math#sinh
  1.1087 +     * sinh(<i>x</i>)}/{@linkplain Math#cosh cosh(<i>x</i>)}.  Note
  1.1088 +     * that the absolute value of the exact tanh is always less than
  1.1089 +     * 1.
  1.1090 +     *
  1.1091 +     * <p>Special cases:
  1.1092 +     * <ul>
  1.1093 +     *
  1.1094 +     * <li>If the argument is NaN, then the result is NaN.
  1.1095 +     *
  1.1096 +     * <li>If the argument is zero, then the result is a zero with the
  1.1097 +     * same sign as the argument.
  1.1098 +     *
  1.1099 +     * <li>If the argument is positive infinity, then the result is
  1.1100 +     * {@code +1.0}.
  1.1101 +     *
  1.1102 +     * <li>If the argument is negative infinity, then the result is
  1.1103 +     * {@code -1.0}.
  1.1104 +     *
  1.1105 +     * </ul>
  1.1106 +     *
  1.1107 +     * @param   x The number whose hyperbolic tangent is to be returned.
  1.1108 +     * @return  The hyperbolic tangent of {@code x}.
  1.1109 +     * @since 1.5
  1.1110 +     */
  1.1111 +    public static native double tanh(double x);
  1.1112 +
  1.1113 +    /**
  1.1114 +     * Returns sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)
  1.1115 +     * without intermediate overflow or underflow.
  1.1116 +     *
  1.1117 +     * <p>Special cases:
  1.1118 +     * <ul>
  1.1119 +     *
  1.1120 +     * <li> If either argument is infinite, then the result
  1.1121 +     * is positive infinity.
  1.1122 +     *
  1.1123 +     * <li> If either argument is NaN and neither argument is infinite,
  1.1124 +     * then the result is NaN.
  1.1125 +     *
  1.1126 +     * </ul>
  1.1127 +     *
  1.1128 +     * @param x a value
  1.1129 +     * @param y a value
  1.1130 +     * @return sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)
  1.1131 +     * without intermediate overflow or underflow
  1.1132 +     * @since 1.5
  1.1133 +     */
  1.1134 +    public static native double hypot(double x, double y);
  1.1135 +
  1.1136 +    /**
  1.1137 +     * Returns <i>e</i><sup>x</sup>&nbsp;-1.  Note that for values of
  1.1138 +     * <i>x</i> near 0, the exact sum of
  1.1139 +     * {@code expm1(x)}&nbsp;+&nbsp;1 is much closer to the true
  1.1140 +     * result of <i>e</i><sup>x</sup> than {@code exp(x)}.
  1.1141 +     *
  1.1142 +     * <p>Special cases:
  1.1143 +     * <ul>
  1.1144 +     * <li>If the argument is NaN, the result is NaN.
  1.1145 +     *
  1.1146 +     * <li>If the argument is positive infinity, then the result is
  1.1147 +     * positive infinity.
  1.1148 +     *
  1.1149 +     * <li>If the argument is negative infinity, then the result is
  1.1150 +     * -1.0.
  1.1151 +     *
  1.1152 +     * <li>If the argument is zero, then the result is a zero with the
  1.1153 +     * same sign as the argument.
  1.1154 +     *
  1.1155 +     * </ul>
  1.1156 +     *
  1.1157 +     * @param   x   the exponent to raise <i>e</i> to in the computation of
  1.1158 +     *              <i>e</i><sup>{@code x}</sup>&nbsp;-1.
  1.1159 +     * @return  the value <i>e</i><sup>{@code x}</sup>&nbsp;-&nbsp;1.
  1.1160 +     * @since 1.5
  1.1161 +     */
  1.1162 +    public static native double expm1(double x);
  1.1163 +
  1.1164 +    /**
  1.1165 +     * Returns the natural logarithm of the sum of the argument and 1.
  1.1166 +     * Note that for small values {@code x}, the result of
  1.1167 +     * {@code log1p(x)} is much closer to the true result of ln(1
  1.1168 +     * + {@code x}) than the floating-point evaluation of
  1.1169 +     * {@code log(1.0+x)}.
  1.1170 +     *
  1.1171 +     * <p>Special cases:
  1.1172 +     * <ul>
  1.1173 +     *
  1.1174 +     * <li>If the argument is NaN or less than -1, then the result is
  1.1175 +     * NaN.
  1.1176 +     *
  1.1177 +     * <li>If the argument is positive infinity, then the result is
  1.1178 +     * positive infinity.
  1.1179 +     *
  1.1180 +     * <li>If the argument is negative one, then the result is
  1.1181 +     * negative infinity.
  1.1182 +     *
  1.1183 +     * <li>If the argument is zero, then the result is a zero with the
  1.1184 +     * same sign as the argument.
  1.1185 +     *
  1.1186 +     * </ul>
  1.1187 +     *
  1.1188 +     * @param   x   a value
  1.1189 +     * @return the value ln({@code x}&nbsp;+&nbsp;1), the natural
  1.1190 +     * log of {@code x}&nbsp;+&nbsp;1
  1.1191 +     * @since 1.5
  1.1192 +     */
  1.1193 +    public static native double log1p(double x);
  1.1194 +
  1.1195 +    /**
  1.1196 +     * Returns the first floating-point argument with the sign of the
  1.1197 +     * second floating-point argument.  For this method, a NaN
  1.1198 +     * {@code sign} argument is always treated as if it were
  1.1199 +     * positive.
  1.1200 +     *
  1.1201 +     * @param magnitude  the parameter providing the magnitude of the result
  1.1202 +     * @param sign   the parameter providing the sign of the result
  1.1203 +     * @return a value with the magnitude of {@code magnitude}
  1.1204 +     * and the sign of {@code sign}.
  1.1205 +     * @since 1.6
  1.1206 +     */
  1.1207 +    public static double copySign(double magnitude, double sign) {
  1.1208 +        return sun.misc.FpUtils.copySign(magnitude, sign);
  1.1209 +    }
  1.1210 +
  1.1211 +    /**
  1.1212 +     * Returns the first floating-point argument with the sign of the
  1.1213 +     * second floating-point argument.  For this method, a NaN
  1.1214 +     * {@code sign} argument is always treated as if it were
  1.1215 +     * positive.
  1.1216 +     *
  1.1217 +     * @param magnitude  the parameter providing the magnitude of the result
  1.1218 +     * @param sign   the parameter providing the sign of the result
  1.1219 +     * @return a value with the magnitude of {@code magnitude}
  1.1220 +     * and the sign of {@code sign}.
  1.1221 +     * @since 1.6
  1.1222 +     */
  1.1223 +    public static float copySign(float magnitude, float sign) {
  1.1224 +        return sun.misc.FpUtils.copySign(magnitude, sign);
  1.1225 +    }
  1.1226 +    /**
  1.1227 +     * Returns the unbiased exponent used in the representation of a
  1.1228 +     * {@code float}.  Special cases:
  1.1229 +     *
  1.1230 +     * <ul>
  1.1231 +     * <li>If the argument is NaN or infinite, then the result is
  1.1232 +     * {@link Float#MAX_EXPONENT} + 1.
  1.1233 +     * <li>If the argument is zero or subnormal, then the result is
  1.1234 +     * {@link Float#MIN_EXPONENT} -1.
  1.1235 +     * </ul>
  1.1236 +     * @param f a {@code float} value
  1.1237 +     * @since 1.6
  1.1238 +     */
  1.1239 +    public static int getExponent(float f) {
  1.1240 +        return sun.misc.FpUtils.getExponent(f);
  1.1241 +    }
  1.1242 +
  1.1243 +    /**
  1.1244 +     * Returns the unbiased exponent used in the representation of a
  1.1245 +     * {@code double}.  Special cases:
  1.1246 +     *
  1.1247 +     * <ul>
  1.1248 +     * <li>If the argument is NaN or infinite, then the result is
  1.1249 +     * {@link Double#MAX_EXPONENT} + 1.
  1.1250 +     * <li>If the argument is zero or subnormal, then the result is
  1.1251 +     * {@link Double#MIN_EXPONENT} -1.
  1.1252 +     * </ul>
  1.1253 +     * @param d a {@code double} value
  1.1254 +     * @since 1.6
  1.1255 +     */
  1.1256 +    public static int getExponent(double d) {
  1.1257 +        return sun.misc.FpUtils.getExponent(d);
  1.1258 +    }
  1.1259 +
  1.1260 +    /**
  1.1261 +     * Returns the floating-point number adjacent to the first
  1.1262 +     * argument in the direction of the second argument.  If both
  1.1263 +     * arguments compare as equal the second argument is returned.
  1.1264 +     *
  1.1265 +     * <p>Special cases:
  1.1266 +     * <ul>
  1.1267 +     * <li> If either argument is a NaN, then NaN is returned.
  1.1268 +     *
  1.1269 +     * <li> If both arguments are signed zeros, {@code direction}
  1.1270 +     * is returned unchanged (as implied by the requirement of
  1.1271 +     * returning the second argument if the arguments compare as
  1.1272 +     * equal).
  1.1273 +     *
  1.1274 +     * <li> If {@code start} is
  1.1275 +     * &plusmn;{@link Double#MIN_VALUE} and {@code direction}
  1.1276 +     * has a value such that the result should have a smaller
  1.1277 +     * magnitude, then a zero with the same sign as {@code start}
  1.1278 +     * is returned.
  1.1279 +     *
  1.1280 +     * <li> If {@code start} is infinite and
  1.1281 +     * {@code direction} has a value such that the result should
  1.1282 +     * have a smaller magnitude, {@link Double#MAX_VALUE} with the
  1.1283 +     * same sign as {@code start} is returned.
  1.1284 +     *
  1.1285 +     * <li> If {@code start} is equal to &plusmn;
  1.1286 +     * {@link Double#MAX_VALUE} and {@code direction} has a
  1.1287 +     * value such that the result should have a larger magnitude, an
  1.1288 +     * infinity with same sign as {@code start} is returned.
  1.1289 +     * </ul>
  1.1290 +     *
  1.1291 +     * @param start  starting floating-point value
  1.1292 +     * @param direction value indicating which of
  1.1293 +     * {@code start}'s neighbors or {@code start} should
  1.1294 +     * be returned
  1.1295 +     * @return The floating-point number adjacent to {@code start} in the
  1.1296 +     * direction of {@code direction}.
  1.1297 +     * @since 1.6
  1.1298 +     */
  1.1299 +    public static double nextAfter(double start, double direction) {
  1.1300 +        return sun.misc.FpUtils.nextAfter(start, direction);
  1.1301 +    }
  1.1302 +
  1.1303 +    /**
  1.1304 +     * Returns the floating-point number adjacent to the first
  1.1305 +     * argument in the direction of the second argument.  If both
  1.1306 +     * arguments compare as equal a value equivalent to the second argument
  1.1307 +     * is returned.
  1.1308 +     *
  1.1309 +     * <p>Special cases:
  1.1310 +     * <ul>
  1.1311 +     * <li> If either argument is a NaN, then NaN is returned.
  1.1312 +     *
  1.1313 +     * <li> If both arguments are signed zeros, a value equivalent
  1.1314 +     * to {@code direction} is returned.
  1.1315 +     *
  1.1316 +     * <li> If {@code start} is
  1.1317 +     * &plusmn;{@link Float#MIN_VALUE} and {@code direction}
  1.1318 +     * has a value such that the result should have a smaller
  1.1319 +     * magnitude, then a zero with the same sign as {@code start}
  1.1320 +     * is returned.
  1.1321 +     *
  1.1322 +     * <li> If {@code start} is infinite and
  1.1323 +     * {@code direction} has a value such that the result should
  1.1324 +     * have a smaller magnitude, {@link Float#MAX_VALUE} with the
  1.1325 +     * same sign as {@code start} is returned.
  1.1326 +     *
  1.1327 +     * <li> If {@code start} is equal to &plusmn;
  1.1328 +     * {@link Float#MAX_VALUE} and {@code direction} has a
  1.1329 +     * value such that the result should have a larger magnitude, an
  1.1330 +     * infinity with same sign as {@code start} is returned.
  1.1331 +     * </ul>
  1.1332 +     *
  1.1333 +     * @param start  starting floating-point value
  1.1334 +     * @param direction value indicating which of
  1.1335 +     * {@code start}'s neighbors or {@code start} should
  1.1336 +     * be returned
  1.1337 +     * @return The floating-point number adjacent to {@code start} in the
  1.1338 +     * direction of {@code direction}.
  1.1339 +     * @since 1.6
  1.1340 +     */
  1.1341 +    public static float nextAfter(float start, double direction) {
  1.1342 +        return sun.misc.FpUtils.nextAfter(start, direction);
  1.1343 +    }
  1.1344 +
  1.1345 +    /**
  1.1346 +     * Returns the floating-point value adjacent to {@code d} in
  1.1347 +     * the direction of positive infinity.  This method is
  1.1348 +     * semantically equivalent to {@code nextAfter(d,
  1.1349 +     * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
  1.1350 +     * implementation may run faster than its equivalent
  1.1351 +     * {@code nextAfter} call.
  1.1352 +     *
  1.1353 +     * <p>Special Cases:
  1.1354 +     * <ul>
  1.1355 +     * <li> If the argument is NaN, the result is NaN.
  1.1356 +     *
  1.1357 +     * <li> If the argument is positive infinity, the result is
  1.1358 +     * positive infinity.
  1.1359 +     *
  1.1360 +     * <li> If the argument is zero, the result is
  1.1361 +     * {@link Double#MIN_VALUE}
  1.1362 +     *
  1.1363 +     * </ul>
  1.1364 +     *
  1.1365 +     * @param d starting floating-point value
  1.1366 +     * @return The adjacent floating-point value closer to positive
  1.1367 +     * infinity.
  1.1368 +     * @since 1.6
  1.1369 +     */
  1.1370 +    public static double nextUp(double d) {
  1.1371 +        return sun.misc.FpUtils.nextUp(d);
  1.1372 +    }
  1.1373 +
  1.1374 +    /**
  1.1375 +     * Returns the floating-point value adjacent to {@code f} in
  1.1376 +     * the direction of positive infinity.  This method is
  1.1377 +     * semantically equivalent to {@code nextAfter(f,
  1.1378 +     * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
  1.1379 +     * implementation may run faster than its equivalent
  1.1380 +     * {@code nextAfter} call.
  1.1381 +     *
  1.1382 +     * <p>Special Cases:
  1.1383 +     * <ul>
  1.1384 +     * <li> If the argument is NaN, the result is NaN.
  1.1385 +     *
  1.1386 +     * <li> If the argument is positive infinity, the result is
  1.1387 +     * positive infinity.
  1.1388 +     *
  1.1389 +     * <li> If the argument is zero, the result is
  1.1390 +     * {@link Float#MIN_VALUE}
  1.1391 +     *
  1.1392 +     * </ul>
  1.1393 +     *
  1.1394 +     * @param f starting floating-point value
  1.1395 +     * @return The adjacent floating-point value closer to positive
  1.1396 +     * infinity.
  1.1397 +     * @since 1.6
  1.1398 +     */
  1.1399 +    public static float nextUp(float f) {
  1.1400 +        return sun.misc.FpUtils.nextUp(f);
  1.1401 +    }
  1.1402 +
  1.1403 +
  1.1404 +    /**
  1.1405 +     * Return {@code d} &times;
  1.1406 +     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
  1.1407 +     * by a single correctly rounded floating-point multiply to a
  1.1408 +     * member of the double value set.  See the Java
  1.1409 +     * Language Specification for a discussion of floating-point
  1.1410 +     * value sets.  If the exponent of the result is between {@link
  1.1411 +     * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
  1.1412 +     * answer is calculated exactly.  If the exponent of the result
  1.1413 +     * would be larger than {@code Double.MAX_EXPONENT}, an
  1.1414 +     * infinity is returned.  Note that if the result is subnormal,
  1.1415 +     * precision may be lost; that is, when {@code scalb(x, n)}
  1.1416 +     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
  1.1417 +     * <i>x</i>.  When the result is non-NaN, the result has the same
  1.1418 +     * sign as {@code d}.
  1.1419 +     *
  1.1420 +     * <p>Special cases:
  1.1421 +     * <ul>
  1.1422 +     * <li> If the first argument is NaN, NaN is returned.
  1.1423 +     * <li> If the first argument is infinite, then an infinity of the
  1.1424 +     * same sign is returned.
  1.1425 +     * <li> If the first argument is zero, then a zero of the same
  1.1426 +     * sign is returned.
  1.1427 +     * </ul>
  1.1428 +     *
  1.1429 +     * @param d number to be scaled by a power of two.
  1.1430 +     * @param scaleFactor power of 2 used to scale {@code d}
  1.1431 +     * @return {@code d} &times; 2<sup>{@code scaleFactor}</sup>
  1.1432 +     * @since 1.6
  1.1433 +     */
  1.1434 +    public static double scalb(double d, int scaleFactor) {
  1.1435 +        return sun.misc.FpUtils.scalb(d, scaleFactor);
  1.1436 +    }
  1.1437 +
  1.1438 +    /**
  1.1439 +     * Return {@code f} &times;
  1.1440 +     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
  1.1441 +     * by a single correctly rounded floating-point multiply to a
  1.1442 +     * member of the float value set.  See the Java
  1.1443 +     * Language Specification for a discussion of floating-point
  1.1444 +     * value sets.  If the exponent of the result is between {@link
  1.1445 +     * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
  1.1446 +     * answer is calculated exactly.  If the exponent of the result
  1.1447 +     * would be larger than {@code Float.MAX_EXPONENT}, an
  1.1448 +     * infinity is returned.  Note that if the result is subnormal,
  1.1449 +     * precision may be lost; that is, when {@code scalb(x, n)}
  1.1450 +     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
  1.1451 +     * <i>x</i>.  When the result is non-NaN, the result has the same
  1.1452 +     * sign as {@code f}.
  1.1453 +     *
  1.1454 +     * <p>Special cases:
  1.1455 +     * <ul>
  1.1456 +     * <li> If the first argument is NaN, NaN is returned.
  1.1457 +     * <li> If the first argument is infinite, then an infinity of the
  1.1458 +     * same sign is returned.
  1.1459 +     * <li> If the first argument is zero, then a zero of the same
  1.1460 +     * sign is returned.
  1.1461 +     * </ul>
  1.1462 +     *
  1.1463 +     * @param f number to be scaled by a power of two.
  1.1464 +     * @param scaleFactor power of 2 used to scale {@code f}
  1.1465 +     * @return {@code f} &times; 2<sup>{@code scaleFactor}</sup>
  1.1466 +     * @since 1.6
  1.1467 +     */
  1.1468 +    public static float scalb(float f, int scaleFactor) {
  1.1469 +        return sun.misc.FpUtils.scalb(f, scaleFactor);
  1.1470 +    }
  1.1471 +}