1 /*
   2  * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.util.Random;
  29 import sun.misc.DoubleConsts;
  30 import jdk.internal.HotSpotIntrinsicCandidate;
  31 
  32 /**
  33  * The class {@code StrictMath} contains methods for performing basic
  34  * numeric operations such as the elementary exponential, logarithm,
  35  * square root, and trigonometric functions.
  36  *
  37  * <p>To help ensure portability of Java programs, the definitions of
  38  * some of the numeric functions in this package require that they
  39  * produce the same results as certain published algorithms. These
  40  * algorithms are available from the well-known network library
  41  * {@code netlib} as the package "Freely Distributable Math
  42  * Library," <a
  43  * href="ftp://ftp.netlib.org/fdlibm.tar">{@code fdlibm}</a>. These
  44  * algorithms, which are written in the C programming language, are
  45  * then to be understood as executed with all floating-point
  46  * operations following the rules of Java floating-point arithmetic.
  47  *
  48  * <p>The Java math library is defined with respect to
  49  * {@code fdlibm} version 5.3. Where {@code fdlibm} provides
  50  * more than one definition for a function (such as
  51  * {@code acos}), use the "IEEE 754 core function" version
  52  * (residing in a file whose name begins with the letter
  53  * {@code e}).  The methods which require {@code fdlibm}
  54  * semantics are {@code sin}, {@code cos}, {@code tan},
  55  * {@code asin}, {@code acos}, {@code atan},
  56  * {@code exp}, {@code log}, {@code log10},
  57  * {@code cbrt}, {@code atan2}, {@code pow},
  58  * {@code sinh}, {@code cosh}, {@code tanh},
  59  * {@code hypot}, {@code expm1}, and {@code log1p}.
  60  *
  61  * <p>
  62  * The platform uses signed two's complement integer arithmetic with
  63  * int and long primitive types.  The developer should choose
  64  * the primitive type to ensure that arithmetic operations consistently
  65  * produce correct results, which in some cases means the operations
  66  * will not overflow the range of values of the computation.
  67  * The best practice is to choose the primitive type and algorithm to avoid
  68  * overflow. In cases where the size is {@code int} or {@code long} and
  69  * overflow errors need to be detected, the methods {@code addExact},
  70  * {@code subtractExact}, {@code multiplyExact}, and {@code toIntExact}
  71  * throw an {@code ArithmeticException} when the results overflow.
  72  * For other arithmetic operations such as divide, absolute value,
  73  * increment by one, decrement by one, and negation overflow occurs only with
  74  * a specific minimum or maximum value and should be checked against
  75  * the minimum or maximum as appropriate.
  76  *
  77  * @author  unascribed
  78  * @author  Joseph D. Darcy
  79  * @since   1.3
  80  */
  81 
  82 public final class StrictMath {
  83 
  84     /**
  85      * Don't let anyone instantiate this class.
  86      */
  87     private StrictMath() {}
  88 
  89     /**
  90      * The {@code double} value that is closer than any other to
  91      * <i>e</i>, the base of the natural logarithms.
  92      */
  93     public static final double E = 2.7182818284590452354;
  94 
  95     /**
  96      * The {@code double} value that is closer than any other to
  97      * <i>pi</i>, the ratio of the circumference of a circle to its
  98      * diameter.
  99      */
 100     public static final double PI = 3.14159265358979323846;
 101 
 102     /**
 103      * Constant by which to multiply an angular value in degrees to obtain an
 104      * angular value in radians.
 105      */
 106     private static final double DEGREES_TO_RADIANS = 0.017453292519943295;
 107 
 108     /**
 109      * Constant by which to multiply an angular value in radians to obtain an
 110      * angular value in degrees.
 111      */
 112 
 113     private static final double RADIANS_TO_DEGREES = 57.29577951308232;
 114 
 115     /**
 116      * Returns the trigonometric sine of an angle. Special cases:
 117      * <ul><li>If the argument is NaN or an infinity, then the
 118      * result is NaN.
 119      * <li>If the argument is zero, then the result is a zero with the
 120      * same sign as the argument.</ul>
 121      *
 122      * @param   a   an angle, in radians.
 123      * @return  the sine of the argument.
 124      */
 125     public static native double sin(double a);
 126 
 127     /**
 128      * Returns the trigonometric cosine of an angle. Special cases:
 129      * <ul><li>If the argument is NaN or an infinity, then the
 130      * result is NaN.</ul>
 131      *
 132      * @param   a   an angle, in radians.
 133      * @return  the cosine of the argument.
 134      */
 135     public static native double cos(double a);
 136 
 137     /**
 138      * Returns the trigonometric tangent of an angle. Special cases:
 139      * <ul><li>If the argument is NaN or an infinity, then the result
 140      * is NaN.
 141      * <li>If the argument is zero, then the result is a zero with the
 142      * same sign as the argument.</ul>
 143      *
 144      * @param   a   an angle, in radians.
 145      * @return  the tangent of the argument.
 146      */
 147     public static native double tan(double a);
 148 
 149     /**
 150      * Returns the arc sine of a value; the returned angle is in the
 151      * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
 152      * <ul><li>If the argument is NaN or its absolute value is greater
 153      * than 1, then the result is NaN.
 154      * <li>If the argument is zero, then the result is a zero with the
 155      * same sign as the argument.</ul>
 156      *
 157      * @param   a   the value whose arc sine is to be returned.
 158      * @return  the arc sine of the argument.
 159      */
 160     public static native double asin(double a);
 161 
 162     /**
 163      * Returns the arc cosine of a value; the returned angle is in the
 164      * range 0.0 through <i>pi</i>.  Special case:
 165      * <ul><li>If the argument is NaN or its absolute value is greater
 166      * than 1, then the result is NaN.</ul>
 167      *
 168      * @param   a   the value whose arc cosine is to be returned.
 169      * @return  the arc cosine of the argument.
 170      */
 171     public static native double acos(double a);
 172 
 173     /**
 174      * Returns the arc tangent of a value; the returned angle is in the
 175      * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
 176      * <ul><li>If the argument is NaN, then the result is NaN.
 177      * <li>If the argument is zero, then the result is a zero with the
 178      * same sign as the argument.</ul>
 179      *
 180      * @param   a   the value whose arc tangent is to be returned.
 181      * @return  the arc tangent of the argument.
 182      */
 183     public static native double atan(double a);
 184 
 185     /**
 186      * Converts an angle measured in degrees to an approximately
 187      * equivalent angle measured in radians.  The conversion from
 188      * degrees to radians is generally inexact.
 189      *
 190      * @param   angdeg   an angle, in degrees
 191      * @return  the measurement of the angle {@code angdeg}
 192      *          in radians.
 193      */
 194     public static strictfp double toRadians(double angdeg) {
 195         // Do not delegate to Math.toRadians(angdeg) because
 196         // this method has the strictfp modifier.
 197         return angdeg * DEGREES_TO_RADIANS;
 198     }
 199 
 200     /**
 201      * Converts an angle measured in radians to an approximately
 202      * equivalent angle measured in degrees.  The conversion from
 203      * radians to degrees is generally inexact; users should
 204      * <i>not</i> expect {@code cos(toRadians(90.0))} to exactly
 205      * equal {@code 0.0}.
 206      *
 207      * @param   angrad   an angle, in radians
 208      * @return  the measurement of the angle {@code angrad}
 209      *          in degrees.
 210      */
 211     public static strictfp double toDegrees(double angrad) {
 212         // Do not delegate to Math.toDegrees(angrad) because
 213         // this method has the strictfp modifier.
 214         return angrad * RADIANS_TO_DEGREES;
 215     }
 216 
 217     /**
 218      * Returns Euler's number <i>e</i> raised to the power of a
 219      * {@code double} value. Special cases:
 220      * <ul><li>If the argument is NaN, the result is NaN.
 221      * <li>If the argument is positive infinity, then the result is
 222      * positive infinity.
 223      * <li>If the argument is negative infinity, then the result is
 224      * positive zero.</ul>
 225      *
 226      * @param   a   the exponent to raise <i>e</i> to.
 227      * @return  the value <i>e</i><sup>{@code a}</sup>,
 228      *          where <i>e</i> is the base of the natural logarithms.
 229      */
 230     public static native double exp(double a);
 231 
 232     /**
 233      * Returns the natural logarithm (base <i>e</i>) of a {@code double}
 234      * value. Special cases:
 235      * <ul><li>If the argument is NaN or less than zero, then the result
 236      * is NaN.
 237      * <li>If the argument is positive infinity, then the result is
 238      * positive infinity.
 239      * <li>If the argument is positive zero or negative zero, then the
 240      * result is negative infinity.</ul>
 241      *
 242      * @param   a   a value
 243      * @return  the value ln&nbsp;{@code a}, the natural logarithm of
 244      *          {@code a}.
 245      */
 246     public static native double log(double a);
 247 
 248     /**
 249      * Returns the base 10 logarithm of a {@code double} value.
 250      * Special cases:
 251      *
 252      * <ul><li>If the argument is NaN or less than zero, then the result
 253      * is NaN.
 254      * <li>If the argument is positive infinity, then the result is
 255      * positive infinity.
 256      * <li>If the argument is positive zero or negative zero, then the
 257      * result is negative infinity.
 258      * <li> If the argument is equal to 10<sup><i>n</i></sup> for
 259      * integer <i>n</i>, then the result is <i>n</i>.
 260      * </ul>
 261      *
 262      * @param   a   a value
 263      * @return  the base 10 logarithm of  {@code a}.
 264      * @since 1.5
 265      */
 266     public static native double log10(double a);
 267 
 268     /**
 269      * Returns the correctly rounded positive square root of a
 270      * {@code double} value.
 271      * Special cases:
 272      * <ul><li>If the argument is NaN or less than zero, then the result
 273      * is NaN.
 274      * <li>If the argument is positive infinity, then the result is positive
 275      * infinity.
 276      * <li>If the argument is positive zero or negative zero, then the
 277      * result is the same as the argument.</ul>
 278      * Otherwise, the result is the {@code double} value closest to
 279      * the true mathematical square root of the argument value.
 280      *
 281      * @param   a   a value.
 282      * @return  the positive square root of {@code a}.
 283      */
 284     @HotSpotIntrinsicCandidate
 285     public static native double sqrt(double a);
 286 
 287     /**
 288      * Returns the cube root of a {@code double} value.  For
 289      * positive finite {@code x}, {@code cbrt(-x) ==
 290      * -cbrt(x)}; that is, the cube root of a negative value is
 291      * the negative of the cube root of that value's magnitude.
 292      * Special cases:
 293      *
 294      * <ul>
 295      *
 296      * <li>If the argument is NaN, then the result is NaN.
 297      *
 298      * <li>If the argument is infinite, then the result is an infinity
 299      * with the same sign as the argument.
 300      *
 301      * <li>If the argument is zero, then the result is a zero with the
 302      * same sign as the argument.
 303      *
 304      * </ul>
 305      *
 306      * @param   a   a value.
 307      * @return  the cube root of {@code a}.
 308      * @since 1.5
 309      */
 310     public static native double cbrt(double a);
 311 
 312     /**
 313      * Computes the remainder operation on two arguments as prescribed
 314      * by the IEEE 754 standard.
 315      * The remainder value is mathematically equal to
 316      * <code>f1&nbsp;-&nbsp;f2</code>&nbsp;&times;&nbsp;<i>n</i>,
 317      * where <i>n</i> is the mathematical integer closest to the exact
 318      * mathematical value of the quotient {@code f1/f2}, and if two
 319      * mathematical integers are equally close to {@code f1/f2},
 320      * then <i>n</i> is the integer that is even. If the remainder is
 321      * zero, its sign is the same as the sign of the first argument.
 322      * Special cases:
 323      * <ul><li>If either argument is NaN, or the first argument is infinite,
 324      * or the second argument is positive zero or negative zero, then the
 325      * result is NaN.
 326      * <li>If the first argument is finite and the second argument is
 327      * infinite, then the result is the same as the first argument.</ul>
 328      *
 329      * @param   f1   the dividend.
 330      * @param   f2   the divisor.
 331      * @return  the remainder when {@code f1} is divided by
 332      *          {@code f2}.
 333      */
 334     public static native double IEEEremainder(double f1, double f2);
 335 
 336     /**
 337      * Returns the smallest (closest to negative infinity)
 338      * {@code double} value that is greater than or equal to the
 339      * argument and is equal to a mathematical integer. Special cases:
 340      * <ul><li>If the argument value is already equal to a
 341      * mathematical integer, then the result is the same as the
 342      * argument.  <li>If the argument is NaN or an infinity or
 343      * positive zero or negative zero, then the result is the same as
 344      * the argument.  <li>If the argument value is less than zero but
 345      * greater than -1.0, then the result is negative zero.</ul> Note
 346      * that the value of {@code StrictMath.ceil(x)} is exactly the
 347      * value of {@code -StrictMath.floor(-x)}.
 348      *
 349      * @param   a   a value.
 350      * @return  the smallest (closest to negative infinity)
 351      *          floating-point value that is greater than or equal to
 352      *          the argument and is equal to a mathematical integer.
 353      */
 354     public static double ceil(double a) {
 355         return floorOrCeil(a, -0.0, 1.0, 1.0);
 356     }
 357 
 358     /**
 359      * Returns the largest (closest to positive infinity)
 360      * {@code double} value that is less than or equal to the
 361      * argument and is equal to a mathematical integer. Special cases:
 362      * <ul><li>If the argument value is already equal to a
 363      * mathematical integer, then the result is the same as the
 364      * argument.  <li>If the argument is NaN or an infinity or
 365      * positive zero or negative zero, then the result is the same as
 366      * the argument.</ul>
 367      *
 368      * @param   a   a value.
 369      * @return  the largest (closest to positive infinity)
 370      *          floating-point value that less than or equal to the argument
 371      *          and is equal to a mathematical integer.
 372      */
 373     public static double floor(double a) {
 374         return floorOrCeil(a, -1.0, 0.0, -1.0);
 375     }
 376 
 377     /**
 378      * Internal method to share logic between floor and ceil.
 379      *
 380      * @param a the value to be floored or ceiled
 381      * @param negativeBoundary result for values in (-1, 0)
 382      * @param positiveBoundary result for values in (0, 1)
 383      * @param increment value to add when the argument is non-integral
 384      */
 385     private static double floorOrCeil(double a,
 386                                       double negativeBoundary,
 387                                       double positiveBoundary,
 388                                       double sign) {
 389         int exponent = Math.getExponent(a);
 390 
 391         if (exponent < 0) {
 392             /*
 393              * Absolute value of argument is less than 1.
 394              * floorOrceil(-0.0) => -0.0
 395              * floorOrceil(+0.0) => +0.0
 396              */
 397             return ((a == 0.0) ? a :
 398                     ( (a < 0.0) ?  negativeBoundary : positiveBoundary) );
 399         } else if (exponent >= 52) {
 400             /*
 401              * Infinity, NaN, or a value so large it must be integral.
 402              */
 403             return a;
 404         }
 405         // Else the argument is either an integral value already XOR it
 406         // has to be rounded to one.
 407         assert exponent >= 0 && exponent <= 51;
 408 
 409         long doppel = Double.doubleToRawLongBits(a);
 410         long mask   = DoubleConsts.SIGNIF_BIT_MASK >> exponent;
 411 
 412         if ( (mask & doppel) == 0L )
 413             return a; // integral value
 414         else {
 415             double result = Double.longBitsToDouble(doppel & (~mask));
 416             if (sign*a > 0.0)
 417                 result = result + sign;
 418             return result;
 419         }
 420     }
 421 
 422     /**
 423      * Returns the {@code double} value that is closest in value
 424      * to the argument and is equal to a mathematical integer. If two
 425      * {@code double} values that are mathematical integers are
 426      * equally close to the value of the argument, the result is the
 427      * integer value that is even. Special cases:
 428      * <ul><li>If the argument value is already equal to a mathematical
 429      * integer, then the result is the same as the argument.
 430      * <li>If the argument is NaN or an infinity or positive zero or negative
 431      * zero, then the result is the same as the argument.</ul>
 432      *
 433      * @param   a   a value.
 434      * @return  the closest floating-point value to {@code a} that is
 435      *          equal to a mathematical integer.
 436      * @author Joseph D. Darcy
 437      */
 438     public static double rint(double a) {
 439         /*
 440          * If the absolute value of a is not less than 2^52, it
 441          * is either a finite integer (the double format does not have
 442          * enough significand bits for a number that large to have any
 443          * fractional portion), an infinity, or a NaN.  In any of
 444          * these cases, rint of the argument is the argument.
 445          *
 446          * Otherwise, the sum (twoToThe52 + a ) will properly round
 447          * away any fractional portion of a since ulp(twoToThe52) ==
 448          * 1.0; subtracting out twoToThe52 from this sum will then be
 449          * exact and leave the rounded integer portion of a.
 450          *
 451          * This method does *not* need to be declared strictfp to get
 452          * fully reproducible results.  Whether or not a method is
 453          * declared strictfp can only make a difference in the
 454          * returned result if some operation would overflow or
 455          * underflow with strictfp semantics.  The operation
 456          * (twoToThe52 + a ) cannot overflow since large values of a
 457          * are screened out; the add cannot underflow since twoToThe52
 458          * is too large.  The subtraction ((twoToThe52 + a ) -
 459          * twoToThe52) will be exact as discussed above and thus
 460          * cannot overflow or meaningfully underflow.  Finally, the
 461          * last multiply in the return statement is by plus or minus
 462          * 1.0, which is exact too.
 463          */
 464         double twoToThe52 = (double)(1L << 52); // 2^52
 465         double sign = Math.copySign(1.0, a); // preserve sign info
 466         a = Math.abs(a);
 467 
 468         if (a < twoToThe52) { // E_min <= ilogb(a) <= 51
 469             a = ((twoToThe52 + a ) - twoToThe52);
 470         }
 471 
 472         return sign * a; // restore original sign
 473     }
 474 
 475     /**
 476      * Returns the angle <i>theta</i> from the conversion of rectangular
 477      * coordinates ({@code x},&nbsp;{@code y}) to polar
 478      * coordinates (r,&nbsp;<i>theta</i>).
 479      * This method computes the phase <i>theta</i> by computing an arc tangent
 480      * of {@code y/x} in the range of -<i>pi</i> to <i>pi</i>. Special
 481      * cases:
 482      * <ul><li>If either argument is NaN, then the result is NaN.
 483      * <li>If the first argument is positive zero and the second argument
 484      * is positive, or the first argument is positive and finite and the
 485      * second argument is positive infinity, then the result is positive
 486      * zero.
 487      * <li>If the first argument is negative zero and the second argument
 488      * is positive, or the first argument is negative and finite and the
 489      * second argument is positive infinity, then the result is negative zero.
 490      * <li>If the first argument is positive zero and the second argument
 491      * is negative, or the first argument is positive and finite and the
 492      * second argument is negative infinity, then the result is the
 493      * {@code double} value closest to <i>pi</i>.
 494      * <li>If the first argument is negative zero and the second argument
 495      * is negative, or the first argument is negative and finite and the
 496      * second argument is negative infinity, then the result is the
 497      * {@code double} value closest to -<i>pi</i>.
 498      * <li>If the first argument is positive and the second argument is
 499      * positive zero or negative zero, or the first argument is positive
 500      * infinity and the second argument is finite, then the result is the
 501      * {@code double} value closest to <i>pi</i>/2.
 502      * <li>If the first argument is negative and the second argument is
 503      * positive zero or negative zero, or the first argument is negative
 504      * infinity and the second argument is finite, then the result is the
 505      * {@code double} value closest to -<i>pi</i>/2.
 506      * <li>If both arguments are positive infinity, then the result is the
 507      * {@code double} value closest to <i>pi</i>/4.
 508      * <li>If the first argument is positive infinity and the second argument
 509      * is negative infinity, then the result is the {@code double}
 510      * value closest to 3*<i>pi</i>/4.
 511      * <li>If the first argument is negative infinity and the second argument
 512      * is positive infinity, then the result is the {@code double} value
 513      * closest to -<i>pi</i>/4.
 514      * <li>If both arguments are negative infinity, then the result is the
 515      * {@code double} value closest to -3*<i>pi</i>/4.</ul>
 516      *
 517      * @param   y   the ordinate coordinate
 518      * @param   x   the abscissa coordinate
 519      * @return  the <i>theta</i> component of the point
 520      *          (<i>r</i>,&nbsp;<i>theta</i>)
 521      *          in polar coordinates that corresponds to the point
 522      *          (<i>x</i>,&nbsp;<i>y</i>) in Cartesian coordinates.
 523      */
 524     public static native double atan2(double y, double x);
 525 
 526     /**
 527      * Returns the value of the first argument raised to the power of the
 528      * second argument. Special cases:
 529      *
 530      * <ul><li>If the second argument is positive or negative zero, then the
 531      * result is 1.0.
 532      * <li>If the second argument is 1.0, then the result is the same as the
 533      * first argument.
 534      * <li>If the second argument is NaN, then the result is NaN.
 535      * <li>If the first argument is NaN and the second argument is nonzero,
 536      * then the result is NaN.
 537      *
 538      * <li>If
 539      * <ul>
 540      * <li>the absolute value of the first argument is greater than 1
 541      * and the second argument is positive infinity, or
 542      * <li>the absolute value of the first argument is less than 1 and
 543      * the second argument is negative infinity,
 544      * </ul>
 545      * then the result is positive infinity.
 546      *
 547      * <li>If
 548      * <ul>
 549      * <li>the absolute value of the first argument is greater than 1 and
 550      * the second argument is negative infinity, or
 551      * <li>the absolute value of the
 552      * first argument is less than 1 and the second argument is positive
 553      * infinity,
 554      * </ul>
 555      * then the result is positive zero.
 556      *
 557      * <li>If the absolute value of the first argument equals 1 and the
 558      * second argument is infinite, then the result is NaN.
 559      *
 560      * <li>If
 561      * <ul>
 562      * <li>the first argument is positive zero and the second argument
 563      * is greater than zero, or
 564      * <li>the first argument is positive infinity and the second
 565      * argument is less than zero,
 566      * </ul>
 567      * then the result is positive zero.
 568      *
 569      * <li>If
 570      * <ul>
 571      * <li>the first argument is positive zero and the second argument
 572      * is less than zero, or
 573      * <li>the first argument is positive infinity and the second
 574      * argument is greater than zero,
 575      * </ul>
 576      * then the result is positive infinity.
 577      *
 578      * <li>If
 579      * <ul>
 580      * <li>the first argument is negative zero and the second argument
 581      * is greater than zero but not a finite odd integer, or
 582      * <li>the first argument is negative infinity and the second
 583      * argument is less than zero but not a finite odd integer,
 584      * </ul>
 585      * then the result is positive zero.
 586      *
 587      * <li>If
 588      * <ul>
 589      * <li>the first argument is negative zero and the second argument
 590      * is a positive finite odd integer, or
 591      * <li>the first argument is negative infinity and the second
 592      * argument is a negative finite odd integer,
 593      * </ul>
 594      * then the result is negative zero.
 595      *
 596      * <li>If
 597      * <ul>
 598      * <li>the first argument is negative zero and the second argument
 599      * is less than zero but not a finite odd integer, or
 600      * <li>the first argument is negative infinity and the second
 601      * argument is greater than zero but not a finite odd integer,
 602      * </ul>
 603      * then the result is positive infinity.
 604      *
 605      * <li>If
 606      * <ul>
 607      * <li>the first argument is negative zero and the second argument
 608      * is a negative finite odd integer, or
 609      * <li>the first argument is negative infinity and the second
 610      * argument is a positive finite odd integer,
 611      * </ul>
 612      * then the result is negative infinity.
 613      *
 614      * <li>If the first argument is finite and less than zero
 615      * <ul>
 616      * <li> if the second argument is a finite even integer, the
 617      * result is equal to the result of raising the absolute value of
 618      * the first argument to the power of the second argument
 619      *
 620      * <li>if the second argument is a finite odd integer, the result
 621      * is equal to the negative of the result of raising the absolute
 622      * value of the first argument to the power of the second
 623      * argument
 624      *
 625      * <li>if the second argument is finite and not an integer, then
 626      * the result is NaN.
 627      * </ul>
 628      *
 629      * <li>If both arguments are integers, then the result is exactly equal
 630      * to the mathematical result of raising the first argument to the power
 631      * of the second argument if that result can in fact be represented
 632      * exactly as a {@code double} value.</ul>
 633      *
 634      * <p>(In the foregoing descriptions, a floating-point value is
 635      * considered to be an integer if and only if it is finite and a
 636      * fixed point of the method {@link #ceil ceil} or,
 637      * equivalently, a fixed point of the method {@link #floor
 638      * floor}. A value is a fixed point of a one-argument
 639      * method if and only if the result of applying the method to the
 640      * value is equal to the value.)
 641      *
 642      * @param   a   base.
 643      * @param   b   the exponent.
 644      * @return  the value {@code a}<sup>{@code b}</sup>.
 645      */
 646     public static double pow(double a, double b) {
 647         return FdLibm.Pow.compute(a, b);
 648     }
 649 
 650     /**
 651      * Returns the closest {@code int} to the argument, with ties
 652      * rounding to positive infinity.
 653      *
 654      * <p>Special cases:
 655      * <ul><li>If the argument is NaN, the result is 0.
 656      * <li>If the argument is negative infinity or any value less than or
 657      * equal to the value of {@code Integer.MIN_VALUE}, the result is
 658      * equal to the value of {@code Integer.MIN_VALUE}.
 659      * <li>If the argument is positive infinity or any value greater than or
 660      * equal to the value of {@code Integer.MAX_VALUE}, the result is
 661      * equal to the value of {@code Integer.MAX_VALUE}.</ul>
 662      *
 663      * @param   a   a floating-point value to be rounded to an integer.
 664      * @return  the value of the argument rounded to the nearest
 665      *          {@code int} value.
 666      * @see     java.lang.Integer#MAX_VALUE
 667      * @see     java.lang.Integer#MIN_VALUE
 668      */
 669     public static int round(float a) {
 670         return Math.round(a);
 671     }
 672 
 673     /**
 674      * Returns the closest {@code long} to the argument, with ties
 675      * rounding to positive infinity.
 676      *
 677      * <p>Special cases:
 678      * <ul><li>If the argument is NaN, the result is 0.
 679      * <li>If the argument is negative infinity or any value less than or
 680      * equal to the value of {@code Long.MIN_VALUE}, the result is
 681      * equal to the value of {@code Long.MIN_VALUE}.
 682      * <li>If the argument is positive infinity or any value greater than or
 683      * equal to the value of {@code Long.MAX_VALUE}, the result is
 684      * equal to the value of {@code Long.MAX_VALUE}.</ul>
 685      *
 686      * @param   a  a floating-point value to be rounded to a
 687      *          {@code long}.
 688      * @return  the value of the argument rounded to the nearest
 689      *          {@code long} value.
 690      * @see     java.lang.Long#MAX_VALUE
 691      * @see     java.lang.Long#MIN_VALUE
 692      */
 693     public static long round(double a) {
 694         return Math.round(a);
 695     }
 696 
 697     private static final class RandomNumberGeneratorHolder {
 698         static final Random randomNumberGenerator = new Random();
 699     }
 700 
 701     /**
 702      * Returns a {@code double} value with a positive sign, greater
 703      * than or equal to {@code 0.0} and less than {@code 1.0}.
 704      * Returned values are chosen pseudorandomly with (approximately)
 705      * uniform distribution from that range.
 706      *
 707      * <p>When this method is first called, it creates a single new
 708      * pseudorandom-number generator, exactly as if by the expression
 709      *
 710      * <blockquote>{@code new java.util.Random()}</blockquote>
 711      *
 712      * This new pseudorandom-number generator is used thereafter for
 713      * all calls to this method and is used nowhere else.
 714      *
 715      * <p>This method is properly synchronized to allow correct use by
 716      * more than one thread. However, if many threads need to generate
 717      * pseudorandom numbers at a great rate, it may reduce contention
 718      * for each thread to have its own pseudorandom-number generator.
 719      *
 720      * @return  a pseudorandom {@code double} greater than or equal
 721      * to {@code 0.0} and less than {@code 1.0}.
 722      * @see Random#nextDouble()
 723      */
 724     public static double random() {
 725         return RandomNumberGeneratorHolder.randomNumberGenerator.nextDouble();
 726     }
 727 
 728     /**
 729      * Returns the sum of its arguments,
 730      * throwing an exception if the result overflows an {@code int}.
 731      *
 732      * @param x the first value
 733      * @param y the second value
 734      * @return the result
 735      * @throws ArithmeticException if the result overflows an int
 736      * @see Math#addExact(int,int)
 737      * @since 1.8
 738      */
 739     public static int addExact(int x, int y) {
 740         return Math.addExact(x, y);
 741     }
 742 
 743     /**
 744      * Returns the sum of its arguments,
 745      * throwing an exception if the result overflows a {@code long}.
 746      *
 747      * @param x the first value
 748      * @param y the second value
 749      * @return the result
 750      * @throws ArithmeticException if the result overflows a long
 751      * @see Math#addExact(long,long)
 752      * @since 1.8
 753      */
 754     public static long addExact(long x, long y) {
 755         return Math.addExact(x, y);
 756     }
 757 
 758     /**
 759      * Returns the difference of the arguments,
 760      * throwing an exception if the result overflows an {@code int}.
 761      *
 762      * @param x the first value
 763      * @param y the second value to subtract from the first
 764      * @return the result
 765      * @throws ArithmeticException if the result overflows an int
 766      * @see Math#subtractExact(int,int)
 767      * @since 1.8
 768      */
 769     public static int subtractExact(int x, int y) {
 770         return Math.subtractExact(x, y);
 771     }
 772 
 773     /**
 774      * Returns the difference of the arguments,
 775      * throwing an exception if the result overflows a {@code long}.
 776      *
 777      * @param x the first value
 778      * @param y the second value to subtract from the first
 779      * @return the result
 780      * @throws ArithmeticException if the result overflows a long
 781      * @see Math#subtractExact(long,long)
 782      * @since 1.8
 783      */
 784     public static long subtractExact(long x, long y) {
 785         return Math.subtractExact(x, y);
 786     }
 787 
 788     /**
 789      * Returns the product of the arguments,
 790      * throwing an exception if the result overflows an {@code int}.
 791      *
 792      * @param x the first value
 793      * @param y the second value
 794      * @return the result
 795      * @throws ArithmeticException if the result overflows an int
 796      * @see Math#multiplyExact(int,int)
 797      * @since 1.8
 798      */
 799     public static int multiplyExact(int x, int y) {
 800         return Math.multiplyExact(x, y);
 801     }
 802 
 803     /**
 804      * Returns the product of the arguments, throwing an exception if the result
 805      * overflows a {@code long}.
 806      *
 807      * @param x the first value
 808      * @param y the second value
 809      * @return the result
 810      * @throws ArithmeticException if the result overflows a long
 811      * @see Math#multiplyExact(long,int)
 812      * @since 1.9
 813      */
 814     public static long multiplyExact(long x, int y) {
 815         return Math.multiplyExact(x, y);
 816     }
 817 
 818     /**
 819      * Returns the product of the arguments,
 820      * throwing an exception if the result overflows a {@code long}.
 821      *
 822      * @param x the first value
 823      * @param y the second value
 824      * @return the result
 825      * @throws ArithmeticException if the result overflows a long
 826      * @see Math#multiplyExact(long,long)
 827      * @since 1.8
 828      */
 829     public static long multiplyExact(long x, long y) {
 830         return Math.multiplyExact(x, y);
 831     }
 832 
 833     /**
 834      * Returns the value of the {@code long} argument;
 835      * throwing an exception if the value overflows an {@code int}.
 836      *
 837      * @param value the long value
 838      * @return the argument as an int
 839      * @throws ArithmeticException if the {@code argument} overflows an int
 840      * @see Math#toIntExact(long)
 841      * @since 1.8
 842      */
 843     public static int toIntExact(long value) {
 844         return Math.toIntExact(value);
 845     }
 846 
 847     /**
 848      * Returns the largest (closest to positive infinity)
 849      * {@code int} value that is less than or equal to the algebraic quotient.
 850      * There is one special case, if the dividend is the
 851      * {@linkplain Integer#MIN_VALUE Integer.MIN_VALUE} and the divisor is {@code -1},
 852      * then integer overflow occurs and
 853      * the result is equal to the {@code Integer.MIN_VALUE}.
 854      * <p>
 855      * See {@link Math#floorDiv(int, int) Math.floorDiv} for examples and
 856      * a comparison to the integer division {@code /} operator.
 857      *
 858      * @param x the dividend
 859      * @param y the divisor
 860      * @return the largest (closest to positive infinity)
 861      * {@code int} value that is less than or equal to the algebraic quotient.
 862      * @throws ArithmeticException if the divisor {@code y} is zero
 863      * @see Math#floorDiv(int, int)
 864      * @see Math#floor(double)
 865      * @since 1.8
 866      */
 867     public static int floorDiv(int x, int y) {
 868         return Math.floorDiv(x, y);
 869     }
 870 
 871     /**
 872      * Returns the largest (closest to positive infinity)
 873      * {@code long} value that is less than or equal to the algebraic quotient.
 874      * There is one special case, if the dividend is the
 875      * {@linkplain Long#MIN_VALUE Long.MIN_VALUE} and the divisor is {@code -1},
 876      * then integer overflow occurs and
 877      * the result is equal to {@code Long.MIN_VALUE}.
 878      * <p>
 879      * See {@link Math#floorDiv(int, int) Math.floorDiv} for examples and
 880      * a comparison to the integer division {@code /} operator.
 881      *
 882      * @param x the dividend
 883      * @param y the divisor
 884      * @return the largest (closest to positive infinity)
 885      * {@code int} value that is less than or equal to the algebraic quotient.
 886      * @throws ArithmeticException if the divisor {@code y} is zero
 887      * @see Math#floorDiv(long, int)
 888      * @see Math#floor(double)
 889      * @since 1.9
 890      */
 891     public static long floorDiv(long x, int y) {
 892         return Math.floorDiv(x, y);
 893     }
 894 
 895     /**
 896      * Returns the largest (closest to positive infinity)
 897      * {@code long} value that is less than or equal to the algebraic quotient.
 898      * There is one special case, if the dividend is the
 899      * {@linkplain Long#MIN_VALUE Long.MIN_VALUE} and the divisor is {@code -1},
 900      * then integer overflow occurs and
 901      * the result is equal to the {@code Long.MIN_VALUE}.
 902      * <p>
 903      * See {@link Math#floorDiv(int, int) Math.floorDiv} for examples and
 904      * a comparison to the integer division {@code /} operator.
 905      *
 906      * @param x the dividend
 907      * @param y the divisor
 908      * @return the largest (closest to positive infinity)
 909      * {@code long} value that is less than or equal to the algebraic quotient.
 910      * @throws ArithmeticException if the divisor {@code y} is zero
 911      * @see Math#floorDiv(long, long)
 912      * @see Math#floor(double)
 913      * @since 1.8
 914      */
 915     public static long floorDiv(long x, long y) {
 916         return Math.floorDiv(x, y);
 917     }
 918 
 919     /**
 920      * Returns the floor modulus of the {@code int} arguments.
 921      * <p>
 922      * The floor modulus is {@code x - (floorDiv(x, y) * y)},
 923      * has the same sign as the divisor {@code y}, and
 924      * is in the range of {@code -abs(y) < r < +abs(y)}.
 925      * <p>
 926      * The relationship between {@code floorDiv} and {@code floorMod} is such that:
 927      * <ul>
 928      *   <li>{@code floorDiv(x, y) * y + floorMod(x, y) == x}
 929      * </ul>
 930      * <p>
 931      * See {@link Math#floorMod(int, int) Math.floorMod} for examples and
 932      * a comparison to the {@code %} operator.
 933      *
 934      * @param x the dividend
 935      * @param y the divisor
 936      * @return the floor modulus {@code x - (floorDiv(x, y) * y)}
 937      * @throws ArithmeticException if the divisor {@code y} is zero
 938      * @see Math#floorMod(int, int)
 939      * @see StrictMath#floorDiv(int, int)
 940      * @since 1.8
 941      */
 942     public static int floorMod(int x, int y) {
 943         return Math.floorMod(x , y);
 944     }
 945 
 946     /**
 947      * Returns the floor modulus of the {@code long} and {@int} arguments.
 948      * <p>
 949      * The floor modulus is {@code x - (floorDiv(x, y) * y)},
 950      * has the same sign as the divisor {@code y}, and
 951      * is in the range of {@code -abs(y) < r < +abs(y)}.
 952      *
 953      * <p>
 954      * The relationship between {@code floorDiv} and {@code floorMod} is such that:
 955      * <ul>
 956      *   <li>{@code floorDiv(x, y) * y + floorMod(x, y) == x}
 957      * </ul>
 958      * <p>
 959      * See {@link Math#floorMod(int, int) Math.floorMod} for examples and
 960      * a comparison to the {@code %} operator.
 961      *
 962      * @param x the dividend
 963      * @param y the divisor
 964      * @return the floor modulus {@code x - (floorDiv(x, y) * y)}
 965      * @throws ArithmeticException if the divisor {@code y} is zero
 966      * @see Math#floorMod(long, int)
 967      * @see StrictMath#floorDiv(long, int)
 968      * @since 1.9
 969      */
 970     public static int floorMod(long x, int y) {
 971         return Math.floorMod(x , y);
 972     }
 973 
 974     /**
 975      * Returns the floor modulus of the {@code long} arguments.
 976      * <p>
 977      * The floor modulus is {@code x - (floorDiv(x, y) * y)},
 978      * has the same sign as the divisor {@code y}, and
 979      * is in the range of {@code -abs(y) < r < +abs(y)}.
 980      * <p>
 981      * The relationship between {@code floorDiv} and {@code floorMod} is such that:
 982      * <ul>
 983      *   <li>{@code floorDiv(x, y) * y + floorMod(x, y) == x}
 984      * </ul>
 985      * <p>
 986      * See {@link Math#floorMod(int, int) Math.floorMod} for examples and
 987      * a comparison to the {@code %} operator.
 988      *
 989      * @param x the dividend
 990      * @param y the divisor
 991      * @return the floor modulus {@code x - (floorDiv(x, y) * y)}
 992      * @throws ArithmeticException if the divisor {@code y} is zero
 993      * @see Math#floorMod(long, long)
 994      * @see StrictMath#floorDiv(long, long)
 995      * @since 1.8
 996      */
 997     public static long floorMod(long x, long y) {
 998         return Math.floorMod(x, y);
 999     }
1000 
1001     /**
1002      * Returns the absolute value of an {@code int} value.
1003      * If the argument is not negative, the argument is returned.
1004      * If the argument is negative, the negation of the argument is returned.
1005      *
1006      * <p>Note that if the argument is equal to the value of
1007      * {@link Integer#MIN_VALUE}, the most negative representable
1008      * {@code int} value, the result is that same value, which is
1009      * negative.
1010      *
1011      * @param   a   the  argument whose absolute value is to be determined.
1012      * @return  the absolute value of the argument.
1013      */
1014     public static int abs(int a) {
1015         return Math.abs(a);
1016     }
1017 
1018     /**
1019      * Returns the absolute value of a {@code long} value.
1020      * If the argument is not negative, the argument is returned.
1021      * If the argument is negative, the negation of the argument is returned.
1022      *
1023      * <p>Note that if the argument is equal to the value of
1024      * {@link Long#MIN_VALUE}, the most negative representable
1025      * {@code long} value, the result is that same value, which
1026      * is negative.
1027      *
1028      * @param   a   the  argument whose absolute value is to be determined.
1029      * @return  the absolute value of the argument.
1030      */
1031     public static long abs(long a) {
1032         return Math.abs(a);
1033     }
1034 
1035     /**
1036      * Returns the absolute value of a {@code float} value.
1037      * If the argument is not negative, the argument is returned.
1038      * If the argument is negative, the negation of the argument is returned.
1039      * Special cases:
1040      * <ul><li>If the argument is positive zero or negative zero, the
1041      * result is positive zero.
1042      * <li>If the argument is infinite, the result is positive infinity.
1043      * <li>If the argument is NaN, the result is NaN.</ul>
1044      * In other words, the result is the same as the value of the expression:
1045      * <p>{@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
1046      *
1047      * @param   a   the argument whose absolute value is to be determined
1048      * @return  the absolute value of the argument.
1049      */
1050     public static float abs(float a) {
1051         return Math.abs(a);
1052     }
1053 
1054     /**
1055      * Returns the absolute value of a {@code double} value.
1056      * If the argument is not negative, the argument is returned.
1057      * If the argument is negative, the negation of the argument is returned.
1058      * Special cases:
1059      * <ul><li>If the argument is positive zero or negative zero, the result
1060      * is positive zero.
1061      * <li>If the argument is infinite, the result is positive infinity.
1062      * <li>If the argument is NaN, the result is NaN.</ul>
1063      * In other words, the result is the same as the value of the expression:
1064      * <p>{@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
1065      *
1066      * @param   a   the argument whose absolute value is to be determined
1067      * @return  the absolute value of the argument.
1068      */
1069     public static double abs(double a) {
1070         return Math.abs(a);
1071     }
1072 
1073     /**
1074      * Returns the greater of two {@code int} values. That is, the
1075      * result is the argument closer to the value of
1076      * {@link Integer#MAX_VALUE}. If the arguments have the same value,
1077      * the result is that same value.
1078      *
1079      * @param   a   an argument.
1080      * @param   b   another argument.
1081      * @return  the larger of {@code a} and {@code b}.
1082      */
1083     @HotSpotIntrinsicCandidate
1084     public static int max(int a, int b) {
1085         return Math.max(a, b);
1086     }
1087 
1088     /**
1089      * Returns the greater of two {@code long} values. That is, the
1090      * result is the argument closer to the value of
1091      * {@link Long#MAX_VALUE}. If the arguments have the same value,
1092      * the result is that same value.
1093      *
1094      * @param   a   an argument.
1095      * @param   b   another argument.
1096      * @return  the larger of {@code a} and {@code b}.
1097         */
1098     public static long max(long a, long b) {
1099         return Math.max(a, b);
1100     }
1101 
1102     /**
1103      * Returns the greater of two {@code float} values.  That is,
1104      * the result is the argument closer to positive infinity. If the
1105      * arguments have the same value, the result is that same
1106      * value. If either value is NaN, then the result is NaN.  Unlike
1107      * the numerical comparison operators, this method considers
1108      * negative zero to be strictly smaller than positive zero. If one
1109      * argument is positive zero and the other negative zero, the
1110      * result is positive zero.
1111      *
1112      * @param   a   an argument.
1113      * @param   b   another argument.
1114      * @return  the larger of {@code a} and {@code b}.
1115      */
1116     public static float max(float a, float b) {
1117         return Math.max(a, b);
1118     }
1119 
1120     /**
1121      * Returns the greater of two {@code double} values.  That
1122      * is, the result is the argument closer to positive infinity. If
1123      * the arguments have the same value, the result is that same
1124      * value. If either value is NaN, then the result is NaN.  Unlike
1125      * the numerical comparison operators, this method considers
1126      * negative zero to be strictly smaller than positive zero. If one
1127      * argument is positive zero and the other negative zero, the
1128      * result is positive zero.
1129      *
1130      * @param   a   an argument.
1131      * @param   b   another argument.
1132      * @return  the larger of {@code a} and {@code b}.
1133      */
1134     public static double max(double a, double b) {
1135         return Math.max(a, b);
1136     }
1137 
1138     /**
1139      * Returns the smaller of two {@code int} values. That is,
1140      * the result the argument closer to the value of
1141      * {@link Integer#MIN_VALUE}.  If the arguments have the same
1142      * value, the result is that same value.
1143      *
1144      * @param   a   an argument.
1145      * @param   b   another argument.
1146      * @return  the smaller of {@code a} and {@code b}.
1147      */
1148     @HotSpotIntrinsicCandidate
1149     public static int min(int a, int b) {
1150         return Math.min(a, b);
1151     }
1152 
1153     /**
1154      * Returns the smaller of two {@code long} values. That is,
1155      * the result is the argument closer to the value of
1156      * {@link Long#MIN_VALUE}. If the arguments have the same
1157      * value, the result is that same value.
1158      *
1159      * @param   a   an argument.
1160      * @param   b   another argument.
1161      * @return  the smaller of {@code a} and {@code b}.
1162      */
1163     public static long min(long a, long b) {
1164         return Math.min(a, b);
1165     }
1166 
1167     /**
1168      * Returns the smaller of two {@code float} values.  That is,
1169      * the result is the value closer to negative infinity. If the
1170      * arguments have the same value, the result is that same
1171      * value. If either value is NaN, then the result is NaN.  Unlike
1172      * the numerical comparison operators, this method considers
1173      * negative zero to be strictly smaller than positive zero.  If
1174      * one argument is positive zero and the other is negative zero,
1175      * the result is negative zero.
1176      *
1177      * @param   a   an argument.
1178      * @param   b   another argument.
1179      * @return  the smaller of {@code a} and {@code b.}
1180      */
1181     public static float min(float a, float b) {
1182         return Math.min(a, b);
1183     }
1184 
1185     /**
1186      * Returns the smaller of two {@code double} values.  That
1187      * is, the result is the value closer to negative infinity. If the
1188      * arguments have the same value, the result is that same
1189      * value. If either value is NaN, then the result is NaN.  Unlike
1190      * the numerical comparison operators, this method considers
1191      * negative zero to be strictly smaller than positive zero. If one
1192      * argument is positive zero and the other is negative zero, the
1193      * result is negative zero.
1194      *
1195      * @param   a   an argument.
1196      * @param   b   another argument.
1197      * @return  the smaller of {@code a} and {@code b}.
1198      */
1199     public static double min(double a, double b) {
1200         return Math.min(a, b);
1201     }
1202 
1203     /**
1204      * Returns the size of an ulp of the argument.  An ulp, unit in
1205      * the last place, of a {@code double} value is the positive
1206      * distance between this floating-point value and the {@code
1207      * double} value next larger in magnitude.  Note that for non-NaN
1208      * <i>x</i>, <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
1209      *
1210      * <p>Special Cases:
1211      * <ul>
1212      * <li> If the argument is NaN, then the result is NaN.
1213      * <li> If the argument is positive or negative infinity, then the
1214      * result is positive infinity.
1215      * <li> If the argument is positive or negative zero, then the result is
1216      * {@code Double.MIN_VALUE}.
1217      * <li> If the argument is &plusmn;{@code Double.MAX_VALUE}, then
1218      * the result is equal to 2<sup>971</sup>.
1219      * </ul>
1220      *
1221      * @param d the floating-point value whose ulp is to be returned
1222      * @return the size of an ulp of the argument
1223      * @author Joseph D. Darcy
1224      * @since 1.5
1225      */
1226     public static double ulp(double d) {
1227         return Math.ulp(d);
1228     }
1229 
1230     /**
1231      * Returns the size of an ulp of the argument.  An ulp, unit in
1232      * the last place, of a {@code float} value is the positive
1233      * distance between this floating-point value and the {@code
1234      * float} value next larger in magnitude.  Note that for non-NaN
1235      * <i>x</i>, <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
1236      *
1237      * <p>Special Cases:
1238      * <ul>
1239      * <li> If the argument is NaN, then the result is NaN.
1240      * <li> If the argument is positive or negative infinity, then the
1241      * result is positive infinity.
1242      * <li> If the argument is positive or negative zero, then the result is
1243      * {@code Float.MIN_VALUE}.
1244      * <li> If the argument is &plusmn;{@code Float.MAX_VALUE}, then
1245      * the result is equal to 2<sup>104</sup>.
1246      * </ul>
1247      *
1248      * @param f the floating-point value whose ulp is to be returned
1249      * @return the size of an ulp of the argument
1250      * @author Joseph D. Darcy
1251      * @since 1.5
1252      */
1253     public static float ulp(float f) {
1254         return Math.ulp(f);
1255     }
1256 
1257     /**
1258      * Returns the signum function of the argument; zero if the argument
1259      * is zero, 1.0 if the argument is greater than zero, -1.0 if the
1260      * argument is less than zero.
1261      *
1262      * <p>Special Cases:
1263      * <ul>
1264      * <li> If the argument is NaN, then the result is NaN.
1265      * <li> If the argument is positive zero or negative zero, then the
1266      *      result is the same as the argument.
1267      * </ul>
1268      *
1269      * @param d the floating-point value whose signum is to be returned
1270      * @return the signum function of the argument
1271      * @author Joseph D. Darcy
1272      * @since 1.5
1273      */
1274     public static double signum(double d) {
1275         return Math.signum(d);
1276     }
1277 
1278     /**
1279      * Returns the signum function of the argument; zero if the argument
1280      * is zero, 1.0f if the argument is greater than zero, -1.0f if the
1281      * argument is less than zero.
1282      *
1283      * <p>Special Cases:
1284      * <ul>
1285      * <li> If the argument is NaN, then the result is NaN.
1286      * <li> If the argument is positive zero or negative zero, then the
1287      *      result is the same as the argument.
1288      * </ul>
1289      *
1290      * @param f the floating-point value whose signum is to be returned
1291      * @return the signum function of the argument
1292      * @author Joseph D. Darcy
1293      * @since 1.5
1294      */
1295     public static float signum(float f) {
1296         return Math.signum(f);
1297     }
1298 
1299     /**
1300      * Returns the hyperbolic sine of a {@code double} value.
1301      * The hyperbolic sine of <i>x</i> is defined to be
1302      * (<i>e<sup>x</sup>&nbsp;-&nbsp;e<sup>-x</sup></i>)/2
1303      * where <i>e</i> is {@linkplain Math#E Euler's number}.
1304      *
1305      * <p>Special cases:
1306      * <ul>
1307      *
1308      * <li>If the argument is NaN, then the result is NaN.
1309      *
1310      * <li>If the argument is infinite, then the result is an infinity
1311      * with the same sign as the argument.
1312      *
1313      * <li>If the argument is zero, then the result is a zero with the
1314      * same sign as the argument.
1315      *
1316      * </ul>
1317      *
1318      * @param   x The number whose hyperbolic sine is to be returned.
1319      * @return  The hyperbolic sine of {@code x}.
1320      * @since 1.5
1321      */
1322     public static native double sinh(double x);
1323 
1324     /**
1325      * Returns the hyperbolic cosine of a {@code double} value.
1326      * The hyperbolic cosine of <i>x</i> is defined to be
1327      * (<i>e<sup>x</sup>&nbsp;+&nbsp;e<sup>-x</sup></i>)/2
1328      * where <i>e</i> is {@linkplain Math#E Euler's number}.
1329      *
1330      * <p>Special cases:
1331      * <ul>
1332      *
1333      * <li>If the argument is NaN, then the result is NaN.
1334      *
1335      * <li>If the argument is infinite, then the result is positive
1336      * infinity.
1337      *
1338      * <li>If the argument is zero, then the result is {@code 1.0}.
1339      *
1340      * </ul>
1341      *
1342      * @param   x The number whose hyperbolic cosine is to be returned.
1343      * @return  The hyperbolic cosine of {@code x}.
1344      * @since 1.5
1345      */
1346     public static native double cosh(double x);
1347 
1348     /**
1349      * Returns the hyperbolic tangent of a {@code double} value.
1350      * The hyperbolic tangent of <i>x</i> is defined to be
1351      * (<i>e<sup>x</sup>&nbsp;-&nbsp;e<sup>-x</sup></i>)/(<i>e<sup>x</sup>&nbsp;+&nbsp;e<sup>-x</sup></i>),
1352      * in other words, {@linkplain Math#sinh
1353      * sinh(<i>x</i>)}/{@linkplain Math#cosh cosh(<i>x</i>)}.  Note
1354      * that the absolute value of the exact tanh is always less than
1355      * 1.
1356      *
1357      * <p>Special cases:
1358      * <ul>
1359      *
1360      * <li>If the argument is NaN, then the result is NaN.
1361      *
1362      * <li>If the argument is zero, then the result is a zero with the
1363      * same sign as the argument.
1364      *
1365      * <li>If the argument is positive infinity, then the result is
1366      * {@code +1.0}.
1367      *
1368      * <li>If the argument is negative infinity, then the result is
1369      * {@code -1.0}.
1370      *
1371      * </ul>
1372      *
1373      * @param   x The number whose hyperbolic tangent is to be returned.
1374      * @return  The hyperbolic tangent of {@code x}.
1375      * @since 1.5
1376      */
1377     public static native double tanh(double x);
1378 
1379     /**
1380      * Returns sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)
1381      * without intermediate overflow or underflow.
1382      *
1383      * <p>Special cases:
1384      * <ul>
1385      *
1386      * <li> If either argument is infinite, then the result
1387      * is positive infinity.
1388      *
1389      * <li> If either argument is NaN and neither argument is infinite,
1390      * then the result is NaN.
1391      *
1392      * </ul>
1393      *
1394      * @param x a value
1395      * @param y a value
1396      * @return sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)
1397      * without intermediate overflow or underflow
1398      * @since 1.5
1399      */
1400     public static double hypot(double x, double y) {
1401         return FdLibm.Hypot.compute(x, y);
1402     }
1403 
1404     /**
1405      * Returns <i>e</i><sup>x</sup>&nbsp;-1.  Note that for values of
1406      * <i>x</i> near 0, the exact sum of
1407      * {@code expm1(x)}&nbsp;+&nbsp;1 is much closer to the true
1408      * result of <i>e</i><sup>x</sup> than {@code exp(x)}.
1409      *
1410      * <p>Special cases:
1411      * <ul>
1412      * <li>If the argument is NaN, the result is NaN.
1413      *
1414      * <li>If the argument is positive infinity, then the result is
1415      * positive infinity.
1416      *
1417      * <li>If the argument is negative infinity, then the result is
1418      * -1.0.
1419      *
1420      * <li>If the argument is zero, then the result is a zero with the
1421      * same sign as the argument.
1422      *
1423      * </ul>
1424      *
1425      * @param   x   the exponent to raise <i>e</i> to in the computation of
1426      *              <i>e</i><sup>{@code x}</sup>&nbsp;-1.
1427      * @return  the value <i>e</i><sup>{@code x}</sup>&nbsp;-&nbsp;1.
1428      * @since 1.5
1429      */
1430     public static native double expm1(double x);
1431 
1432     /**
1433      * Returns the natural logarithm of the sum of the argument and 1.
1434      * Note that for small values {@code x}, the result of
1435      * {@code log1p(x)} is much closer to the true result of ln(1
1436      * + {@code x}) than the floating-point evaluation of
1437      * {@code log(1.0+x)}.
1438      *
1439      * <p>Special cases:
1440      * <ul>
1441      *
1442      * <li>If the argument is NaN or less than -1, then the result is
1443      * NaN.
1444      *
1445      * <li>If the argument is positive infinity, then the result is
1446      * positive infinity.
1447      *
1448      * <li>If the argument is negative one, then the result is
1449      * negative infinity.
1450      *
1451      * <li>If the argument is zero, then the result is a zero with the
1452      * same sign as the argument.
1453      *
1454      * </ul>
1455      *
1456      * @param   x   a value
1457      * @return the value ln({@code x}&nbsp;+&nbsp;1), the natural
1458      * log of {@code x}&nbsp;+&nbsp;1
1459      * @since 1.5
1460      */
1461     public static native double log1p(double x);
1462 
1463     /**
1464      * Returns the first floating-point argument with the sign of the
1465      * second floating-point argument.  For this method, a NaN
1466      * {@code sign} argument is always treated as if it were
1467      * positive.
1468      *
1469      * @param magnitude  the parameter providing the magnitude of the result
1470      * @param sign   the parameter providing the sign of the result
1471      * @return a value with the magnitude of {@code magnitude}
1472      * and the sign of {@code sign}.
1473      * @since 1.6
1474      */
1475     public static double copySign(double magnitude, double sign) {
1476         return Math.copySign(magnitude, (Double.isNaN(sign)?1.0d:sign));
1477     }
1478 
1479     /**
1480      * Returns the first floating-point argument with the sign of the
1481      * second floating-point argument.  For this method, a NaN
1482      * {@code sign} argument is always treated as if it were
1483      * positive.
1484      *
1485      * @param magnitude  the parameter providing the magnitude of the result
1486      * @param sign   the parameter providing the sign of the result
1487      * @return a value with the magnitude of {@code magnitude}
1488      * and the sign of {@code sign}.
1489      * @since 1.6
1490      */
1491     public static float copySign(float magnitude, float sign) {
1492         return Math.copySign(magnitude, (Float.isNaN(sign)?1.0f:sign));
1493     }
1494     /**
1495      * Returns the unbiased exponent used in the representation of a
1496      * {@code float}.  Special cases:
1497      *
1498      * <ul>
1499      * <li>If the argument is NaN or infinite, then the result is
1500      * {@link Float#MAX_EXPONENT} + 1.
1501      * <li>If the argument is zero or subnormal, then the result is
1502      * {@link Float#MIN_EXPONENT} -1.
1503      * </ul>
1504      * @param f a {@code float} value
1505      * @return the unbiased exponent of the argument
1506      * @since 1.6
1507      */
1508     public static int getExponent(float f) {
1509         return Math.getExponent(f);
1510     }
1511 
1512     /**
1513      * Returns the unbiased exponent used in the representation of a
1514      * {@code double}.  Special cases:
1515      *
1516      * <ul>
1517      * <li>If the argument is NaN or infinite, then the result is
1518      * {@link Double#MAX_EXPONENT} + 1.
1519      * <li>If the argument is zero or subnormal, then the result is
1520      * {@link Double#MIN_EXPONENT} -1.
1521      * </ul>
1522      * @param d a {@code double} value
1523      * @return the unbiased exponent of the argument
1524      * @since 1.6
1525      */
1526     public static int getExponent(double d) {
1527         return Math.getExponent(d);
1528     }
1529 
1530     /**
1531      * Returns the floating-point number adjacent to the first
1532      * argument in the direction of the second argument.  If both
1533      * arguments compare as equal the second argument is returned.
1534      *
1535      * <p>Special cases:
1536      * <ul>
1537      * <li> If either argument is a NaN, then NaN is returned.
1538      *
1539      * <li> If both arguments are signed zeros, {@code direction}
1540      * is returned unchanged (as implied by the requirement of
1541      * returning the second argument if the arguments compare as
1542      * equal).
1543      *
1544      * <li> If {@code start} is
1545      * &plusmn;{@link Double#MIN_VALUE} and {@code direction}
1546      * has a value such that the result should have a smaller
1547      * magnitude, then a zero with the same sign as {@code start}
1548      * is returned.
1549      *
1550      * <li> If {@code start} is infinite and
1551      * {@code direction} has a value such that the result should
1552      * have a smaller magnitude, {@link Double#MAX_VALUE} with the
1553      * same sign as {@code start} is returned.
1554      *
1555      * <li> If {@code start} is equal to &plusmn;
1556      * {@link Double#MAX_VALUE} and {@code direction} has a
1557      * value such that the result should have a larger magnitude, an
1558      * infinity with same sign as {@code start} is returned.
1559      * </ul>
1560      *
1561      * @param start  starting floating-point value
1562      * @param direction value indicating which of
1563      * {@code start}'s neighbors or {@code start} should
1564      * be returned
1565      * @return The floating-point number adjacent to {@code start} in the
1566      * direction of {@code direction}.
1567      * @since 1.6
1568      */
1569     public static double nextAfter(double start, double direction) {
1570         return Math.nextAfter(start, direction);
1571     }
1572 
1573     /**
1574      * Returns the floating-point number adjacent to the first
1575      * argument in the direction of the second argument.  If both
1576      * arguments compare as equal a value equivalent to the second argument
1577      * is returned.
1578      *
1579      * <p>Special cases:
1580      * <ul>
1581      * <li> If either argument is a NaN, then NaN is returned.
1582      *
1583      * <li> If both arguments are signed zeros, a value equivalent
1584      * to {@code direction} is returned.
1585      *
1586      * <li> If {@code start} is
1587      * &plusmn;{@link Float#MIN_VALUE} and {@code direction}
1588      * has a value such that the result should have a smaller
1589      * magnitude, then a zero with the same sign as {@code start}
1590      * is returned.
1591      *
1592      * <li> If {@code start} is infinite and
1593      * {@code direction} has a value such that the result should
1594      * have a smaller magnitude, {@link Float#MAX_VALUE} with the
1595      * same sign as {@code start} is returned.
1596      *
1597      * <li> If {@code start} is equal to &plusmn;
1598      * {@link Float#MAX_VALUE} and {@code direction} has a
1599      * value such that the result should have a larger magnitude, an
1600      * infinity with same sign as {@code start} is returned.
1601      * </ul>
1602      *
1603      * @param start  starting floating-point value
1604      * @param direction value indicating which of
1605      * {@code start}'s neighbors or {@code start} should
1606      * be returned
1607      * @return The floating-point number adjacent to {@code start} in the
1608      * direction of {@code direction}.
1609      * @since 1.6
1610      */
1611     public static float nextAfter(float start, double direction) {
1612         return Math.nextAfter(start, direction);
1613     }
1614 
1615     /**
1616      * Returns the floating-point value adjacent to {@code d} in
1617      * the direction of positive infinity.  This method is
1618      * semantically equivalent to {@code nextAfter(d,
1619      * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
1620      * implementation may run faster than its equivalent
1621      * {@code nextAfter} call.
1622      *
1623      * <p>Special Cases:
1624      * <ul>
1625      * <li> If the argument is NaN, the result is NaN.
1626      *
1627      * <li> If the argument is positive infinity, the result is
1628      * positive infinity.
1629      *
1630      * <li> If the argument is zero, the result is
1631      * {@link Double#MIN_VALUE}
1632      *
1633      * </ul>
1634      *
1635      * @param d starting floating-point value
1636      * @return The adjacent floating-point value closer to positive
1637      * infinity.
1638      * @since 1.6
1639      */
1640     public static double nextUp(double d) {
1641         return Math.nextUp(d);
1642     }
1643 
1644     /**
1645      * Returns the floating-point value adjacent to {@code f} in
1646      * the direction of positive infinity.  This method is
1647      * semantically equivalent to {@code nextAfter(f,
1648      * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
1649      * implementation may run faster than its equivalent
1650      * {@code nextAfter} call.
1651      *
1652      * <p>Special Cases:
1653      * <ul>
1654      * <li> If the argument is NaN, the result is NaN.
1655      *
1656      * <li> If the argument is positive infinity, the result is
1657      * positive infinity.
1658      *
1659      * <li> If the argument is zero, the result is
1660      * {@link Float#MIN_VALUE}
1661      *
1662      * </ul>
1663      *
1664      * @param f starting floating-point value
1665      * @return The adjacent floating-point value closer to positive
1666      * infinity.
1667      * @since 1.6
1668      */
1669     public static float nextUp(float f) {
1670         return Math.nextUp(f);
1671     }
1672 
1673     /**
1674      * Returns the floating-point value adjacent to {@code d} in
1675      * the direction of negative infinity.  This method is
1676      * semantically equivalent to {@code nextAfter(d,
1677      * Double.NEGATIVE_INFINITY)}; however, a
1678      * {@code nextDown} implementation may run faster than its
1679      * equivalent {@code nextAfter} call.
1680      *
1681      * <p>Special Cases:
1682      * <ul>
1683      * <li> If the argument is NaN, the result is NaN.
1684      *
1685      * <li> If the argument is negative infinity, the result is
1686      * negative infinity.
1687      *
1688      * <li> If the argument is zero, the result is
1689      * {@code -Double.MIN_VALUE}
1690      *
1691      * </ul>
1692      *
1693      * @param d  starting floating-point value
1694      * @return The adjacent floating-point value closer to negative
1695      * infinity.
1696      * @since 1.8
1697      */
1698     public static double nextDown(double d) {
1699         return Math.nextDown(d);
1700     }
1701 
1702     /**
1703      * Returns the floating-point value adjacent to {@code f} in
1704      * the direction of negative infinity.  This method is
1705      * semantically equivalent to {@code nextAfter(f,
1706      * Float.NEGATIVE_INFINITY)}; however, a
1707      * {@code nextDown} implementation may run faster than its
1708      * equivalent {@code nextAfter} call.
1709      *
1710      * <p>Special Cases:
1711      * <ul>
1712      * <li> If the argument is NaN, the result is NaN.
1713      *
1714      * <li> If the argument is negative infinity, the result is
1715      * negative infinity.
1716      *
1717      * <li> If the argument is zero, the result is
1718      * {@code -Float.MIN_VALUE}
1719      *
1720      * </ul>
1721      *
1722      * @param f  starting floating-point value
1723      * @return The adjacent floating-point value closer to negative
1724      * infinity.
1725      * @since 1.8
1726      */
1727     public static float nextDown(float f) {
1728         return Math.nextDown(f);
1729     }
1730 
1731     /**
1732      * Returns {@code d} &times;
1733      * 2<sup>{@code scaleFactor}</sup> rounded as if performed
1734      * by a single correctly rounded floating-point multiply to a
1735      * member of the double value set.  See the Java
1736      * Language Specification for a discussion of floating-point
1737      * value sets.  If the exponent of the result is between {@link
1738      * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
1739      * answer is calculated exactly.  If the exponent of the result
1740      * would be larger than {@code Double.MAX_EXPONENT}, an
1741      * infinity is returned.  Note that if the result is subnormal,
1742      * precision may be lost; that is, when {@code scalb(x, n)}
1743      * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
1744      * <i>x</i>.  When the result is non-NaN, the result has the same
1745      * sign as {@code d}.
1746      *
1747      * <p>Special cases:
1748      * <ul>
1749      * <li> If the first argument is NaN, NaN is returned.
1750      * <li> If the first argument is infinite, then an infinity of the
1751      * same sign is returned.
1752      * <li> If the first argument is zero, then a zero of the same
1753      * sign is returned.
1754      * </ul>
1755      *
1756      * @param d number to be scaled by a power of two.
1757      * @param scaleFactor power of 2 used to scale {@code d}
1758      * @return {@code d} &times; 2<sup>{@code scaleFactor}</sup>
1759      * @since 1.6
1760      */
1761     public static double scalb(double d, int scaleFactor) {
1762         return Math.scalb(d, scaleFactor);
1763     }
1764 
1765     /**
1766      * Returns {@code f} &times;
1767      * 2<sup>{@code scaleFactor}</sup> rounded as if performed
1768      * by a single correctly rounded floating-point multiply to a
1769      * member of the float value set.  See the Java
1770      * Language Specification for a discussion of floating-point
1771      * value sets.  If the exponent of the result is between {@link
1772      * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
1773      * answer is calculated exactly.  If the exponent of the result
1774      * would be larger than {@code Float.MAX_EXPONENT}, an
1775      * infinity is returned.  Note that if the result is subnormal,
1776      * precision may be lost; that is, when {@code scalb(x, n)}
1777      * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
1778      * <i>x</i>.  When the result is non-NaN, the result has the same
1779      * sign as {@code f}.
1780      *
1781      * <p>Special cases:
1782      * <ul>
1783      * <li> If the first argument is NaN, NaN is returned.
1784      * <li> If the first argument is infinite, then an infinity of the
1785      * same sign is returned.
1786      * <li> If the first argument is zero, then a zero of the same
1787      * sign is returned.
1788      * </ul>
1789      *
1790      * @param f number to be scaled by a power of two.
1791      * @param scaleFactor power of 2 used to scale {@code f}
1792      * @return {@code f} &times; 2<sup>{@code scaleFactor}</sup>
1793      * @since 1.6
1794      */
1795     public static float scalb(float f, int scaleFactor) {
1796         return Math.scalb(f, scaleFactor);
1797     }
1798 }