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 jdk.internal.math.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, decrement, 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 double cbrt(double a) {
 311         return FdLibm.Cbrt.compute(a);
 312     }
 313 
 314     /**
 315      * Computes the remainder operation on two arguments as prescribed
 316      * by the IEEE 754 standard.
 317      * The remainder value is mathematically equal to
 318      * <code>f1&nbsp;-&nbsp;f2</code>&nbsp;&times;&nbsp;<i>n</i>,
 319      * where <i>n</i> is the mathematical integer closest to the exact
 320      * mathematical value of the quotient {@code f1/f2}, and if two
 321      * mathematical integers are equally close to {@code f1/f2},
 322      * then <i>n</i> is the integer that is even. If the remainder is
 323      * zero, its sign is the same as the sign of the first argument.
 324      * Special cases:
 325      * <ul><li>If either argument is NaN, or the first argument is infinite,
 326      * or the second argument is positive zero or negative zero, then the
 327      * result is NaN.
 328      * <li>If the first argument is finite and the second argument is
 329      * infinite, then the result is the same as the first argument.</ul>
 330      *
 331      * @param   f1   the dividend.
 332      * @param   f2   the divisor.
 333      * @return  the remainder when {@code f1} is divided by
 334      *          {@code f2}.
 335      */
 336     public static native double IEEEremainder(double f1, double f2);
 337 
 338     /**
 339      * Returns the smallest (closest to negative infinity)
 340      * {@code double} value that is greater than or equal to the
 341      * argument and is equal to a mathematical integer. Special cases:
 342      * <ul><li>If the argument value is already equal to a
 343      * mathematical integer, then the result is the same as the
 344      * argument.  <li>If the argument is NaN or an infinity or
 345      * positive zero or negative zero, then the result is the same as
 346      * the argument.  <li>If the argument value is less than zero but
 347      * greater than -1.0, then the result is negative zero.</ul> Note
 348      * that the value of {@code StrictMath.ceil(x)} is exactly the
 349      * value of {@code -StrictMath.floor(-x)}.
 350      *
 351      * @param   a   a value.
 352      * @return  the smallest (closest to negative infinity)
 353      *          floating-point value that is greater than or equal to
 354      *          the argument and is equal to a mathematical integer.
 355      */
 356     public static double ceil(double a) {
 357         return floorOrCeil(a, -0.0, 1.0, 1.0);
 358     }
 359 
 360     /**
 361      * Returns the largest (closest to positive infinity)
 362      * {@code double} value that is less than or equal to the
 363      * argument and is equal to a mathematical integer. Special cases:
 364      * <ul><li>If the argument value is already equal to a
 365      * mathematical integer, then the result is the same as the
 366      * argument.  <li>If the argument is NaN or an infinity or
 367      * positive zero or negative zero, then the result is the same as
 368      * the argument.</ul>
 369      *
 370      * @param   a   a value.
 371      * @return  the largest (closest to positive infinity)
 372      *          floating-point value that less than or equal to the argument
 373      *          and is equal to a mathematical integer.
 374      */
 375     public static double floor(double a) {
 376         return floorOrCeil(a, -1.0, 0.0, -1.0);
 377     }
 378 
 379     /**
 380      * Internal method to share logic between floor and ceil.
 381      *
 382      * @param a the value to be floored or ceiled
 383      * @param negativeBoundary result for values in (-1, 0)
 384      * @param positiveBoundary result for values in (0, 1)
 385      * @param increment value to add when the argument is non-integral
 386      */
 387     private static double floorOrCeil(double a,
 388                                       double negativeBoundary,
 389                                       double positiveBoundary,
 390                                       double sign) {
 391         int exponent = Math.getExponent(a);
 392 
 393         if (exponent < 0) {
 394             /*
 395              * Absolute value of argument is less than 1.
 396              * floorOrceil(-0.0) => -0.0
 397              * floorOrceil(+0.0) => +0.0
 398              */
 399             return ((a == 0.0) ? a :
 400                     ( (a < 0.0) ?  negativeBoundary : positiveBoundary) );
 401         } else if (exponent >= 52) {
 402             /*
 403              * Infinity, NaN, or a value so large it must be integral.
 404              */
 405             return a;
 406         }
 407         // Else the argument is either an integral value already XOR it
 408         // has to be rounded to one.
 409         assert exponent >= 0 && exponent <= 51;
 410 
 411         long doppel = Double.doubleToRawLongBits(a);
 412         long mask   = DoubleConsts.SIGNIF_BIT_MASK >> exponent;
 413 
 414         if ( (mask & doppel) == 0L )
 415             return a; // integral value
 416         else {
 417             double result = Double.longBitsToDouble(doppel & (~mask));
 418             if (sign*a > 0.0)
 419                 result = result + sign;
 420             return result;
 421         }
 422     }
 423 
 424     /**
 425      * Returns the {@code double} value that is closest in value
 426      * to the argument and is equal to a mathematical integer. If two
 427      * {@code double} values that are mathematical integers are
 428      * equally close to the value of the argument, the result is the
 429      * integer value that is even. Special cases:
 430      * <ul><li>If the argument value is already equal to a mathematical
 431      * integer, then the result is the same as the argument.
 432      * <li>If the argument is NaN or an infinity or positive zero or negative
 433      * zero, then the result is the same as the argument.</ul>
 434      *
 435      * @param   a   a value.
 436      * @return  the closest floating-point value to {@code a} that is
 437      *          equal to a mathematical integer.
 438      * @author Joseph D. Darcy
 439      */
 440     public static double rint(double a) {
 441         /*
 442          * If the absolute value of a is not less than 2^52, it
 443          * is either a finite integer (the double format does not have
 444          * enough significand bits for a number that large to have any
 445          * fractional portion), an infinity, or a NaN.  In any of
 446          * these cases, rint of the argument is the argument.
 447          *
 448          * Otherwise, the sum (twoToThe52 + a ) will properly round
 449          * away any fractional portion of a since ulp(twoToThe52) ==
 450          * 1.0; subtracting out twoToThe52 from this sum will then be
 451          * exact and leave the rounded integer portion of a.
 452          *
 453          * This method does *not* need to be declared strictfp to get
 454          * fully reproducible results.  Whether or not a method is
 455          * declared strictfp can only make a difference in the
 456          * returned result if some operation would overflow or
 457          * underflow with strictfp semantics.  The operation
 458          * (twoToThe52 + a ) cannot overflow since large values of a
 459          * are screened out; the add cannot underflow since twoToThe52
 460          * is too large.  The subtraction ((twoToThe52 + a ) -
 461          * twoToThe52) will be exact as discussed above and thus
 462          * cannot overflow or meaningfully underflow.  Finally, the
 463          * last multiply in the return statement is by plus or minus
 464          * 1.0, which is exact too.
 465          */
 466         double twoToThe52 = (double)(1L << 52); // 2^52
 467         double sign = Math.copySign(1.0, a); // preserve sign info
 468         a = Math.abs(a);
 469 
 470         if (a < twoToThe52) { // E_min <= ilogb(a) <= 51
 471             a = ((twoToThe52 + a ) - twoToThe52);
 472         }
 473 
 474         return sign * a; // restore original sign
 475     }
 476 
 477     /**
 478      * Returns the angle <i>theta</i> from the conversion of rectangular
 479      * coordinates ({@code x},&nbsp;{@code y}) to polar
 480      * coordinates (r,&nbsp;<i>theta</i>).
 481      * This method computes the phase <i>theta</i> by computing an arc tangent
 482      * of {@code y/x} in the range of -<i>pi</i> to <i>pi</i>. Special
 483      * cases:
 484      * <ul><li>If either argument is NaN, then the result is NaN.
 485      * <li>If the first argument is positive zero and the second argument
 486      * is positive, or the first argument is positive and finite and the
 487      * second argument is positive infinity, then the result is positive
 488      * zero.
 489      * <li>If the first argument is negative zero and the second argument
 490      * is positive, or the first argument is negative and finite and the
 491      * second argument is positive infinity, then the result is negative zero.
 492      * <li>If the first argument is positive zero and the second argument
 493      * is negative, or the first argument is positive and finite and the
 494      * second argument is negative infinity, then the result is the
 495      * {@code double} value closest to <i>pi</i>.
 496      * <li>If the first argument is negative zero and the second argument
 497      * is negative, or the first argument is negative and finite and the
 498      * second argument is negative infinity, then the result is the
 499      * {@code double} value closest to -<i>pi</i>.
 500      * <li>If the first argument is positive and the second argument is
 501      * positive zero or negative zero, or the first argument is positive
 502      * infinity and the second argument is finite, then the result is the
 503      * {@code double} value closest to <i>pi</i>/2.
 504      * <li>If the first argument is negative and the second argument is
 505      * positive zero or negative zero, or the first argument is negative
 506      * infinity and the second argument is finite, then the result is the
 507      * {@code double} value closest to -<i>pi</i>/2.
 508      * <li>If both arguments are positive infinity, then the result is the
 509      * {@code double} value closest to <i>pi</i>/4.
 510      * <li>If the first argument is positive infinity and the second argument
 511      * is negative infinity, then the result is the {@code double}
 512      * value closest to 3*<i>pi</i>/4.
 513      * <li>If the first argument is negative infinity and the second argument
 514      * is positive infinity, then the result is the {@code double} value
 515      * closest to -<i>pi</i>/4.
 516      * <li>If both arguments are negative infinity, then the result is the
 517      * {@code double} value closest to -3*<i>pi</i>/4.</ul>
 518      *
 519      * @param   y   the ordinate coordinate
 520      * @param   x   the abscissa coordinate
 521      * @return  the <i>theta</i> component of the point
 522      *          (<i>r</i>,&nbsp;<i>theta</i>)
 523      *          in polar coordinates that corresponds to the point
 524      *          (<i>x</i>,&nbsp;<i>y</i>) in Cartesian coordinates.
 525      */
 526     public static native double atan2(double y, double x);
 527 
 528     /**
 529      * Returns the value of the first argument raised to the power of the
 530      * second argument. Special cases:
 531      *
 532      * <ul><li>If the second argument is positive or negative zero, then the
 533      * result is 1.0.
 534      * <li>If the second argument is 1.0, then the result is the same as the
 535      * first argument.
 536      * <li>If the second argument is NaN, then the result is NaN.
 537      * <li>If the first argument is NaN and the second argument is nonzero,
 538      * then the result is NaN.
 539      *
 540      * <li>If
 541      * <ul>
 542      * <li>the absolute value of the first argument is greater than 1
 543      * and the second argument is positive infinity, or
 544      * <li>the absolute value of the first argument is less than 1 and
 545      * the second argument is negative infinity,
 546      * </ul>
 547      * then the result is positive infinity.
 548      *
 549      * <li>If
 550      * <ul>
 551      * <li>the absolute value of the first argument is greater than 1 and
 552      * the second argument is negative infinity, or
 553      * <li>the absolute value of the
 554      * first argument is less than 1 and the second argument is positive
 555      * infinity,
 556      * </ul>
 557      * then the result is positive zero.
 558      *
 559      * <li>If the absolute value of the first argument equals 1 and the
 560      * second argument is infinite, then the result is NaN.
 561      *
 562      * <li>If
 563      * <ul>
 564      * <li>the first argument is positive zero and the second argument
 565      * is greater than zero, or
 566      * <li>the first argument is positive infinity and the second
 567      * argument is less than zero,
 568      * </ul>
 569      * then the result is positive zero.
 570      *
 571      * <li>If
 572      * <ul>
 573      * <li>the first argument is positive zero and the second argument
 574      * is less than zero, or
 575      * <li>the first argument is positive infinity and the second
 576      * argument is greater than zero,
 577      * </ul>
 578      * then the result is positive infinity.
 579      *
 580      * <li>If
 581      * <ul>
 582      * <li>the first argument is negative zero and the second argument
 583      * is greater than zero but not a finite odd integer, or
 584      * <li>the first argument is negative infinity and the second
 585      * argument is less than zero but not a finite odd integer,
 586      * </ul>
 587      * then the result is positive zero.
 588      *
 589      * <li>If
 590      * <ul>
 591      * <li>the first argument is negative zero and the second argument
 592      * is a positive finite odd integer, or
 593      * <li>the first argument is negative infinity and the second
 594      * argument is a negative finite odd integer,
 595      * </ul>
 596      * then the result is negative zero.
 597      *
 598      * <li>If
 599      * <ul>
 600      * <li>the first argument is negative zero and the second argument
 601      * is less than zero but not a finite odd integer, or
 602      * <li>the first argument is negative infinity and the second
 603      * argument is greater than zero but not a finite odd integer,
 604      * </ul>
 605      * then the result is positive infinity.
 606      *
 607      * <li>If
 608      * <ul>
 609      * <li>the first argument is negative zero and the second argument
 610      * is a negative finite odd integer, or
 611      * <li>the first argument is negative infinity and the second
 612      * argument is a positive finite odd integer,
 613      * </ul>
 614      * then the result is negative infinity.
 615      *
 616      * <li>If the first argument is finite and less than zero
 617      * <ul>
 618      * <li> if the second argument is a finite even integer, the
 619      * result is equal to the result of raising the absolute value of
 620      * the first argument to the power of the second argument
 621      *
 622      * <li>if the second argument is a finite odd integer, the result
 623      * is equal to the negative of the result of raising the absolute
 624      * value of the first argument to the power of the second
 625      * argument
 626      *
 627      * <li>if the second argument is finite and not an integer, then
 628      * the result is NaN.
 629      * </ul>
 630      *
 631      * <li>If both arguments are integers, then the result is exactly equal
 632      * to the mathematical result of raising the first argument to the power
 633      * of the second argument if that result can in fact be represented
 634      * exactly as a {@code double} value.</ul>
 635      *
 636      * <p>(In the foregoing descriptions, a floating-point value is
 637      * considered to be an integer if and only if it is finite and a
 638      * fixed point of the method {@link #ceil ceil} or,
 639      * equivalently, a fixed point of the method {@link #floor
 640      * floor}. A value is a fixed point of a one-argument
 641      * method if and only if the result of applying the method to the
 642      * value is equal to the value.)
 643      *
 644      * @param   a   base.
 645      * @param   b   the exponent.
 646      * @return  the value {@code a}<sup>{@code b}</sup>.
 647      */
 648     public static double pow(double a, double b) {
 649         return FdLibm.Pow.compute(a, b);
 650     }
 651 
 652     /**
 653      * Returns the closest {@code int} to the argument, with ties
 654      * rounding to positive infinity.
 655      *
 656      * <p>Special cases:
 657      * <ul><li>If the argument is NaN, the result is 0.
 658      * <li>If the argument is negative infinity or any value less than or
 659      * equal to the value of {@code Integer.MIN_VALUE}, the result is
 660      * equal to the value of {@code Integer.MIN_VALUE}.
 661      * <li>If the argument is positive infinity or any value greater than or
 662      * equal to the value of {@code Integer.MAX_VALUE}, the result is
 663      * equal to the value of {@code Integer.MAX_VALUE}.</ul>
 664      *
 665      * @param   a   a floating-point value to be rounded to an integer.
 666      * @return  the value of the argument rounded to the nearest
 667      *          {@code int} value.
 668      * @see     java.lang.Integer#MAX_VALUE
 669      * @see     java.lang.Integer#MIN_VALUE
 670      */
 671     public static int round(float a) {
 672         return Math.round(a);
 673     }
 674 
 675     /**
 676      * Returns the closest {@code long} to the argument, with ties
 677      * rounding to positive infinity.
 678      *
 679      * <p>Special cases:
 680      * <ul><li>If the argument is NaN, the result is 0.
 681      * <li>If the argument is negative infinity or any value less than or
 682      * equal to the value of {@code Long.MIN_VALUE}, the result is
 683      * equal to the value of {@code Long.MIN_VALUE}.
 684      * <li>If the argument is positive infinity or any value greater than or
 685      * equal to the value of {@code Long.MAX_VALUE}, the result is
 686      * equal to the value of {@code Long.MAX_VALUE}.</ul>
 687      *
 688      * @param   a  a floating-point value to be rounded to a
 689      *          {@code long}.
 690      * @return  the value of the argument rounded to the nearest
 691      *          {@code long} value.
 692      * @see     java.lang.Long#MAX_VALUE
 693      * @see     java.lang.Long#MIN_VALUE
 694      */
 695     public static long round(double a) {
 696         return Math.round(a);
 697     }
 698 
 699     private static final class RandomNumberGeneratorHolder {
 700         static final Random randomNumberGenerator = new Random();
 701     }
 702 
 703     /**
 704      * Returns a {@code double} value with a positive sign, greater
 705      * than or equal to {@code 0.0} and less than {@code 1.0}.
 706      * Returned values are chosen pseudorandomly with (approximately)
 707      * uniform distribution from that range.
 708      *
 709      * <p>When this method is first called, it creates a single new
 710      * pseudorandom-number generator, exactly as if by the expression
 711      *
 712      * <blockquote>{@code new java.util.Random()}</blockquote>
 713      *
 714      * This new pseudorandom-number generator is used thereafter for
 715      * all calls to this method and is used nowhere else.
 716      *
 717      * <p>This method is properly synchronized to allow correct use by
 718      * more than one thread. However, if many threads need to generate
 719      * pseudorandom numbers at a great rate, it may reduce contention
 720      * for each thread to have its own pseudorandom-number generator.
 721      *
 722      * @return  a pseudorandom {@code double} greater than or equal
 723      * to {@code 0.0} and less than {@code 1.0}.
 724      * @see Random#nextDouble()
 725      */
 726     public static double random() {
 727         return RandomNumberGeneratorHolder.randomNumberGenerator.nextDouble();
 728     }
 729 
 730     /**
 731      * Returns the sum of its arguments,
 732      * throwing an exception if the result overflows an {@code int}.
 733      *
 734      * @param x the first value
 735      * @param y the second value
 736      * @return the result
 737      * @throws ArithmeticException if the result overflows an int
 738      * @see Math#addExact(int,int)
 739      * @since 1.8
 740      */
 741     public static int addExact(int x, int y) {
 742         return Math.addExact(x, y);
 743     }
 744 
 745     /**
 746      * Returns the sum of its arguments,
 747      * throwing an exception if the result overflows a {@code long}.
 748      *
 749      * @param x the first value
 750      * @param y the second value
 751      * @return the result
 752      * @throws ArithmeticException if the result overflows a long
 753      * @see Math#addExact(long,long)
 754      * @since 1.8
 755      */
 756     public static long addExact(long x, long y) {
 757         return Math.addExact(x, y);
 758     }
 759 
 760     /**
 761      * Returns the difference of the arguments,
 762      * throwing an exception if the result overflows an {@code int}.
 763      *
 764      * @param x the first value
 765      * @param y the second value to subtract from the first
 766      * @return the result
 767      * @throws ArithmeticException if the result overflows an int
 768      * @see Math#subtractExact(int,int)
 769      * @since 1.8
 770      */
 771     public static int subtractExact(int x, int y) {
 772         return Math.subtractExact(x, y);
 773     }
 774 
 775     /**
 776      * Returns the difference of the arguments,
 777      * throwing an exception if the result overflows a {@code long}.
 778      *
 779      * @param x the first value
 780      * @param y the second value to subtract from the first
 781      * @return the result
 782      * @throws ArithmeticException if the result overflows a long
 783      * @see Math#subtractExact(long,long)
 784      * @since 1.8
 785      */
 786     public static long subtractExact(long x, long y) {
 787         return Math.subtractExact(x, y);
 788     }
 789 
 790     /**
 791      * Returns the product of the arguments,
 792      * throwing an exception if the result overflows an {@code int}.
 793      *
 794      * @param x the first value
 795      * @param y the second value
 796      * @return the result
 797      * @throws ArithmeticException if the result overflows an int
 798      * @see Math#multiplyExact(int,int)
 799      * @since 1.8
 800      */
 801     public static int multiplyExact(int x, int y) {
 802         return Math.multiplyExact(x, y);
 803     }
 804 
 805     /**
 806      * Returns the product of the arguments,
 807      * throwing an exception if the result overflows a {@code long}.
 808      *
 809      * @param x the first value
 810      * @param y the second value
 811      * @return the result
 812      * @throws ArithmeticException if the result overflows a long
 813      * @see Math#multiplyExact(long,long)
 814      * @since 1.8
 815      */
 816     public static long multiplyExact(long x, long y) {
 817         return Math.multiplyExact(x, y);
 818     }
 819 
 820     /**
 821      * Returns the value of the {@code long} argument;
 822      * throwing an exception if the value overflows an {@code int}.
 823      *
 824      * @param value the long value
 825      * @return the argument as an int
 826      * @throws ArithmeticException if the {@code argument} overflows an int
 827      * @see Math#toIntExact(long)
 828      * @since 1.8
 829      */
 830     public static int toIntExact(long value) {
 831         return Math.toIntExact(value);
 832     }
 833 
 834     /**
 835      * Returns the largest (closest to positive infinity)
 836      * {@code int} value that is less than or equal to the algebraic quotient.
 837      * There is one special case, if the dividend is the
 838      * {@linkplain Integer#MIN_VALUE Integer.MIN_VALUE} and the divisor is {@code -1},
 839      * then integer overflow occurs and
 840      * the result is equal to the {@code Integer.MIN_VALUE}.
 841      * <p>
 842      * See {@link Math#floorDiv(int, int) Math.floorDiv} for examples and
 843      * a comparison to the integer division {@code /} operator.
 844      *
 845      * @param x the dividend
 846      * @param y the divisor
 847      * @return the largest (closest to positive infinity)
 848      * {@code int} value that is less than or equal to the algebraic quotient.
 849      * @throws ArithmeticException if the divisor {@code y} is zero
 850      * @see Math#floorDiv(int, int)
 851      * @see Math#floor(double)
 852      * @since 1.8
 853      */
 854     public static int floorDiv(int x, int y) {
 855         return Math.floorDiv(x, y);
 856     }
 857 
 858     /**
 859      * Returns the largest (closest to positive infinity)
 860      * {@code long} value that is less than or equal to the algebraic quotient.
 861      * There is one special case, if the dividend is the
 862      * {@linkplain Long#MIN_VALUE Long.MIN_VALUE} and the divisor is {@code -1},
 863      * then integer overflow occurs and
 864      * the result is equal to the {@code Long.MIN_VALUE}.
 865      * <p>
 866      * See {@link Math#floorDiv(int, int) Math.floorDiv} for examples and
 867      * a comparison to the integer division {@code /} operator.
 868      *
 869      * @param x the dividend
 870      * @param y the divisor
 871      * @return the largest (closest to positive infinity)
 872      * {@code long} value that is less than or equal to the algebraic quotient.
 873      * @throws ArithmeticException if the divisor {@code y} is zero
 874      * @see Math#floorDiv(long, long)
 875      * @see Math#floor(double)
 876      * @since 1.8
 877      */
 878     public static long floorDiv(long x, long y) {
 879         return Math.floorDiv(x, y);
 880     }
 881 
 882     /**
 883      * Returns the floor modulus of the {@code int} arguments.
 884      * <p>
 885      * The floor modulus is {@code x - (floorDiv(x, y) * y)},
 886      * has the same sign as the divisor {@code y}, and
 887      * is in the range of {@code -abs(y) < r < +abs(y)}.
 888      * <p>
 889      * The relationship between {@code floorDiv} and {@code floorMod} is such that:
 890      * <ul>
 891      *   <li>{@code floorDiv(x, y) * y + floorMod(x, y) == x}
 892      * </ul>
 893      * <p>
 894      * See {@link Math#floorMod(int, int) Math.floorMod} for examples and
 895      * a comparison to the {@code %} operator.
 896      *
 897      * @param x the dividend
 898      * @param y the divisor
 899      * @return the floor modulus {@code x - (floorDiv(x, y) * y)}
 900      * @throws ArithmeticException if the divisor {@code y} is zero
 901      * @see Math#floorMod(int, int)
 902      * @see StrictMath#floorDiv(int, int)
 903      * @since 1.8
 904      */
 905     public static int floorMod(int x, int y) {
 906         return Math.floorMod(x , y);
 907     }
 908     /**
 909      * Returns the floor modulus of the {@code long} arguments.
 910      * <p>
 911      * The floor modulus is {@code x - (floorDiv(x, y) * y)},
 912      * has the same sign as the divisor {@code y}, and
 913      * is in the range of {@code -abs(y) < r < +abs(y)}.
 914      * <p>
 915      * The relationship between {@code floorDiv} and {@code floorMod} is such that:
 916      * <ul>
 917      *   <li>{@code floorDiv(x, y) * y + floorMod(x, y) == x}
 918      * </ul>
 919      * <p>
 920      * See {@link Math#floorMod(int, int) Math.floorMod} for examples and
 921      * a comparison to the {@code %} operator.
 922      *
 923      * @param x the dividend
 924      * @param y the divisor
 925      * @return the floor modulus {@code x - (floorDiv(x, y) * y)}
 926      * @throws ArithmeticException if the divisor {@code y} is zero
 927      * @see Math#floorMod(long, long)
 928      * @see StrictMath#floorDiv(long, long)
 929      * @since 1.8
 930      */
 931     public static long floorMod(long x, long y) {
 932         return Math.floorMod(x, y);
 933     }
 934 
 935     /**
 936      * Returns the absolute value of an {@code int} value.
 937      * If the argument is not negative, the argument is returned.
 938      * If the argument is negative, the negation of the argument is returned.
 939      *
 940      * <p>Note that if the argument is equal to the value of
 941      * {@link Integer#MIN_VALUE}, the most negative representable
 942      * {@code int} value, the result is that same value, which is
 943      * negative.
 944      *
 945      * @param   a   the  argument whose absolute value is to be determined.
 946      * @return  the absolute value of the argument.
 947      */
 948     public static int abs(int a) {
 949         return Math.abs(a);
 950     }
 951 
 952     /**
 953      * Returns the absolute value of a {@code long} value.
 954      * If the argument is not negative, the argument is returned.
 955      * If the argument is negative, the negation of the argument is returned.
 956      *
 957      * <p>Note that if the argument is equal to the value of
 958      * {@link Long#MIN_VALUE}, the most negative representable
 959      * {@code long} value, the result is that same value, which
 960      * is negative.
 961      *
 962      * @param   a   the  argument whose absolute value is to be determined.
 963      * @return  the absolute value of the argument.
 964      */
 965     public static long abs(long a) {
 966         return Math.abs(a);
 967     }
 968 
 969     /**
 970      * Returns the absolute value of a {@code float} value.
 971      * If the argument is not negative, the argument is returned.
 972      * If the argument is negative, the negation of the argument is returned.
 973      * Special cases:
 974      * <ul><li>If the argument is positive zero or negative zero, the
 975      * result is positive zero.
 976      * <li>If the argument is infinite, the result is positive infinity.
 977      * <li>If the argument is NaN, the result is NaN.</ul>
 978      * In other words, the result is the same as the value of the expression:
 979      * <p>{@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
 980      *
 981      * @param   a   the argument whose absolute value is to be determined
 982      * @return  the absolute value of the argument.
 983      */
 984     public static float abs(float a) {
 985         return Math.abs(a);
 986     }
 987 
 988     /**
 989      * Returns the absolute value of a {@code double} value.
 990      * If the argument is not negative, the argument is returned.
 991      * If the argument is negative, the negation of the argument is returned.
 992      * Special cases:
 993      * <ul><li>If the argument is positive zero or negative zero, the result
 994      * is positive zero.
 995      * <li>If the argument is infinite, the result is positive infinity.
 996      * <li>If the argument is NaN, the result is NaN.</ul>
 997      * In other words, the result is the same as the value of the expression:
 998      * <p>{@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
 999      *
1000      * @param   a   the argument whose absolute value is to be determined
1001      * @return  the absolute value of the argument.
1002      */
1003     public static double abs(double a) {
1004         return Math.abs(a);
1005     }
1006 
1007     /**
1008      * Returns the greater of two {@code int} values. That is, the
1009      * result is the argument closer to the value of
1010      * {@link Integer#MAX_VALUE}. If the arguments have the same value,
1011      * the result is that same value.
1012      *
1013      * @param   a   an argument.
1014      * @param   b   another argument.
1015      * @return  the larger of {@code a} and {@code b}.
1016      */
1017     @HotSpotIntrinsicCandidate
1018     public static int max(int a, int b) {
1019         return Math.max(a, b);
1020     }
1021 
1022     /**
1023      * Returns the greater of two {@code long} values. That is, the
1024      * result is the argument closer to the value of
1025      * {@link Long#MAX_VALUE}. If the arguments have the same value,
1026      * the result is that same value.
1027      *
1028      * @param   a   an argument.
1029      * @param   b   another argument.
1030      * @return  the larger of {@code a} and {@code b}.
1031         */
1032     public static long max(long a, long b) {
1033         return Math.max(a, b);
1034     }
1035 
1036     /**
1037      * Returns the greater of two {@code float} values.  That is,
1038      * the result is the argument closer to positive infinity. If the
1039      * arguments have the same value, the result is that same
1040      * value. If either value is NaN, then the result is NaN.  Unlike
1041      * the numerical comparison operators, this method considers
1042      * negative zero to be strictly smaller than positive zero. If one
1043      * argument is positive zero and the other negative zero, the
1044      * result is positive zero.
1045      *
1046      * @param   a   an argument.
1047      * @param   b   another argument.
1048      * @return  the larger of {@code a} and {@code b}.
1049      */
1050     public static float max(float a, float b) {
1051         return Math.max(a, b);
1052     }
1053 
1054     /**
1055      * Returns the greater of two {@code double} values.  That
1056      * is, the result is the argument closer to positive infinity. If
1057      * the arguments have the same value, the result is that same
1058      * value. If either value is NaN, then the result is NaN.  Unlike
1059      * the numerical comparison operators, this method considers
1060      * negative zero to be strictly smaller than positive zero. If one
1061      * argument is positive zero and the other negative zero, the
1062      * result is positive zero.
1063      *
1064      * @param   a   an argument.
1065      * @param   b   another argument.
1066      * @return  the larger of {@code a} and {@code b}.
1067      */
1068     public static double max(double a, double b) {
1069         return Math.max(a, b);
1070     }
1071 
1072     /**
1073      * Returns the smaller of two {@code int} values. That is,
1074      * the result the argument closer to the value of
1075      * {@link Integer#MIN_VALUE}.  If the arguments have the same
1076      * value, the result is that same value.
1077      *
1078      * @param   a   an argument.
1079      * @param   b   another argument.
1080      * @return  the smaller of {@code a} and {@code b}.
1081      */
1082     @HotSpotIntrinsicCandidate
1083     public static int min(int a, int b) {
1084         return Math.min(a, b);
1085     }
1086 
1087     /**
1088      * Returns the smaller of two {@code long} values. That is,
1089      * the result is the argument closer to the value of
1090      * {@link Long#MIN_VALUE}. If the arguments have the same
1091      * value, the result is that same value.
1092      *
1093      * @param   a   an argument.
1094      * @param   b   another argument.
1095      * @return  the smaller of {@code a} and {@code b}.
1096      */
1097     public static long min(long a, long b) {
1098         return Math.min(a, b);
1099     }
1100 
1101     /**
1102      * Returns the smaller of two {@code float} values.  That is,
1103      * the result is the value closer to negative infinity. If the
1104      * arguments have the same value, the result is that same
1105      * value. If either value is NaN, then the result is NaN.  Unlike
1106      * the numerical comparison operators, this method considers
1107      * negative zero to be strictly smaller than positive zero.  If
1108      * one argument is positive zero and the other is negative zero,
1109      * the result is negative zero.
1110      *
1111      * @param   a   an argument.
1112      * @param   b   another argument.
1113      * @return  the smaller of {@code a} and {@code b.}
1114      */
1115     public static float min(float a, float b) {
1116         return Math.min(a, b);
1117     }
1118 
1119     /**
1120      * Returns the smaller of two {@code double} values.  That
1121      * is, the result is the value closer to negative infinity. If the
1122      * arguments have the same value, the result is that same
1123      * value. If either value is NaN, then the result is NaN.  Unlike
1124      * the numerical comparison operators, this method considers
1125      * negative zero to be strictly smaller than positive zero. If one
1126      * argument is positive zero and the other is negative zero, the
1127      * result is negative zero.
1128      *
1129      * @param   a   an argument.
1130      * @param   b   another argument.
1131      * @return  the smaller of {@code a} and {@code b}.
1132      */
1133     public static double min(double a, double b) {
1134         return Math.min(a, b);
1135     }
1136 
1137     /**
1138      * Returns the fused multiply add of the three arguments; that is,
1139      * returns the exact product of the first two arguments summed
1140      * with the third argument and then rounded once to the nearest
1141      * {@code double}.
1142      *
1143      * The rounding is done using the {@linkplain
1144      * java.math.RoundingMode#HALF_EVEN round to nearest even
1145      * rounding mode}.
1146      *
1147      * In contrast, if {@code a * b + c} is evaluated as a regular
1148      * floating-point expression, two rounding errors are involved,
1149      * the first for the multiply operation, the second for the
1150      * addition operation.
1151      *
1152      * <p>Special cases:
1153      * <ul>
1154      * <li> If any argument is NaN, the result is NaN.
1155      *
1156      * <li> If one of the first two arguments is infinite and the
1157      * other is zero, the result is NaN.
1158      *
1159      * <li> If the exact product of the first two arguments is infinite
1160      * (in other words, at least one of the arguments is infinite and
1161      * the other is neither zero nor NaN) and the third argument is an
1162      * infinity of the opposite sign, the result is NaN.
1163      *
1164      * </ul>
1165      *
1166      * <p>Note that {@code fusedMac(a, 1.0, c)} returns the same
1167      * result as ({@code a + c}).  However,
1168      * {@code fusedMac(a, b, +0.0)} does <em>not</em> always return the
1169      * same result as ({@code a * b}) since
1170      * {@code fusedMac(-0.0, +0.0, +0.0)} is {@code +0.0} while
1171      * ({@code -0.0 * +0.0}) is {@code -0.0}; {@code fusedMac(a, b, -0.0)} is
1172      * equivalent to ({@code a * b}) however.
1173      *
1174      * @apiNote This method corresponds to the fusedMultiplyAdd
1175      * operation defined in IEEE 754-2008.
1176      *
1177      * @param a a value
1178      * @param b a value
1179      * @param c a value
1180      *
1181      * @return (<i>a</i>&nbsp;&times;&nbsp;<i>b</i>&nbsp;+&nbsp;<i>c</i>)
1182      * computed, as if with unlimited range and precision, and rounded
1183      * once to the nearest {@code double} value
1184      */
1185     public static double fma(double a, double b, double c) {
1186         return Math.fma(a, b, c);
1187     }
1188 
1189     /**
1190      * Returns the fused multiply add of the three arguments; that is,
1191      * returns the exact product of the first two arguments summed
1192      * with the third argument and then rounded once to the nearest
1193      * {@code float}.
1194      *
1195      * The rounding is done using the {@linkplain
1196      * java.math.RoundingMode#HALF_EVEN round to nearest even
1197      * rounding mode}.
1198      *
1199      * In contrast, if {@code a * b + c} is evaluated as a regular
1200      * floating-point expression, two rounding errors are involved,
1201      * the first for the multiply operation, the second for the
1202      * addition operation.
1203      *
1204      * <p>Special cases:
1205      * <ul>
1206      * <li> If any argument is NaN, the result is NaN.
1207      *
1208      * <li> If one of the first two arguments is infinite and the
1209      * other is zero, the result is NaN.
1210      *
1211      * <li> If the exact product of the first two arguments is infinite
1212      * (in other words, at least one of the arguments is infinite and
1213      * the other is neither zero nor NaN) and the third argument is an
1214      * infinity of the opposite sign, the result is NaN.
1215      *
1216      * </ul>
1217      *
1218      * <p>Note that {@code fma(a, 1.0f, c)} returns the same
1219      * result as ({@code a + c}).  However,
1220      * {@code fma(a, b, +0.0f)} does <em>not</em> always return the
1221      * same result as ({@code a * b}) since
1222      * {@code fma(-0.0f, +0.0f, +0.0f)} is {@code +0.0f} while
1223      * ({@code -0.0f * +0.0f}) is {@code -0.0f}; {@code fma(a, b, -0.0f)} is
1224      * equivalent to ({@code a * b}) however.
1225      *
1226      * @apiNote This method corresponds to the fusedMultiplyAdd
1227      * operation defined in IEEE 754-2008.
1228      *
1229      * @param a a value
1230      * @param b a value
1231      * @param c a value
1232      *
1233      * @return (<i>a</i>&nbsp;&times;&nbsp;<i>b</i>&nbsp;+&nbsp;<i>c</i>)
1234      * computed, as if with unlimited range and precision, and rounded
1235      * once to the nearest {@code float} value
1236      */
1237     public static float fma(float a, float b, float c) {
1238         return Math.fma(a, b, c);
1239     }
1240 
1241     /**
1242      * Returns the size of an ulp of the argument.  An ulp, unit in
1243      * the last place, of a {@code double} value is the positive
1244      * distance between this floating-point value and the {@code
1245      * double} value next larger in magnitude.  Note that for non-NaN
1246      * <i>x</i>, <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
1247      *
1248      * <p>Special Cases:
1249      * <ul>
1250      * <li> If the argument is NaN, then the result is NaN.
1251      * <li> If the argument is positive or negative infinity, then the
1252      * result is positive infinity.
1253      * <li> If the argument is positive or negative zero, then the result is
1254      * {@code Double.MIN_VALUE}.
1255      * <li> If the argument is &plusmn;{@code Double.MAX_VALUE}, then
1256      * the result is equal to 2<sup>971</sup>.
1257      * </ul>
1258      *
1259      * @param d the floating-point value whose ulp is to be returned
1260      * @return the size of an ulp of the argument
1261      * @author Joseph D. Darcy
1262      * @since 1.5
1263      */
1264     public static double ulp(double d) {
1265         return Math.ulp(d);
1266     }
1267 
1268     /**
1269      * Returns the size of an ulp of the argument.  An ulp, unit in
1270      * the last place, of a {@code float} value is the positive
1271      * distance between this floating-point value and the {@code
1272      * float} value next larger in magnitude.  Note that for non-NaN
1273      * <i>x</i>, <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
1274      *
1275      * <p>Special Cases:
1276      * <ul>
1277      * <li> If the argument is NaN, then the result is NaN.
1278      * <li> If the argument is positive or negative infinity, then the
1279      * result is positive infinity.
1280      * <li> If the argument is positive or negative zero, then the result is
1281      * {@code Float.MIN_VALUE}.
1282      * <li> If the argument is &plusmn;{@code Float.MAX_VALUE}, then
1283      * the result is equal to 2<sup>104</sup>.
1284      * </ul>
1285      *
1286      * @param f the floating-point value whose ulp is to be returned
1287      * @return the size of an ulp of the argument
1288      * @author Joseph D. Darcy
1289      * @since 1.5
1290      */
1291     public static float ulp(float f) {
1292         return Math.ulp(f);
1293     }
1294 
1295     /**
1296      * Returns the signum function of the argument; zero if the argument
1297      * is zero, 1.0 if the argument is greater than zero, -1.0 if the
1298      * argument is less than zero.
1299      *
1300      * <p>Special Cases:
1301      * <ul>
1302      * <li> If the argument is NaN, then the result is NaN.
1303      * <li> If the argument is positive zero or negative zero, then the
1304      *      result is the same as the argument.
1305      * </ul>
1306      *
1307      * @param d the floating-point value whose signum is to be returned
1308      * @return the signum function of the argument
1309      * @author Joseph D. Darcy
1310      * @since 1.5
1311      */
1312     public static double signum(double d) {
1313         return Math.signum(d);
1314     }
1315 
1316     /**
1317      * Returns the signum function of the argument; zero if the argument
1318      * is zero, 1.0f if the argument is greater than zero, -1.0f if the
1319      * argument is less than zero.
1320      *
1321      * <p>Special Cases:
1322      * <ul>
1323      * <li> If the argument is NaN, then the result is NaN.
1324      * <li> If the argument is positive zero or negative zero, then the
1325      *      result is the same as the argument.
1326      * </ul>
1327      *
1328      * @param f the floating-point value whose signum is to be returned
1329      * @return the signum function of the argument
1330      * @author Joseph D. Darcy
1331      * @since 1.5
1332      */
1333     public static float signum(float f) {
1334         return Math.signum(f);
1335     }
1336 
1337     /**
1338      * Returns the hyperbolic sine of a {@code double} value.
1339      * The hyperbolic sine of <i>x</i> is defined to be
1340      * (<i>e<sup>x</sup>&nbsp;-&nbsp;e<sup>-x</sup></i>)/2
1341      * where <i>e</i> is {@linkplain Math#E Euler's number}.
1342      *
1343      * <p>Special cases:
1344      * <ul>
1345      *
1346      * <li>If the argument is NaN, then the result is NaN.
1347      *
1348      * <li>If the argument is infinite, then the result is an infinity
1349      * with the same sign as the argument.
1350      *
1351      * <li>If the argument is zero, then the result is a zero with the
1352      * same sign as the argument.
1353      *
1354      * </ul>
1355      *
1356      * @param   x The number whose hyperbolic sine is to be returned.
1357      * @return  The hyperbolic sine of {@code x}.
1358      * @since 1.5
1359      */
1360     public static native double sinh(double x);
1361 
1362     /**
1363      * Returns the hyperbolic cosine of a {@code double} value.
1364      * The hyperbolic cosine of <i>x</i> is defined to be
1365      * (<i>e<sup>x</sup>&nbsp;+&nbsp;e<sup>-x</sup></i>)/2
1366      * where <i>e</i> is {@linkplain Math#E Euler's number}.
1367      *
1368      * <p>Special cases:
1369      * <ul>
1370      *
1371      * <li>If the argument is NaN, then the result is NaN.
1372      *
1373      * <li>If the argument is infinite, then the result is positive
1374      * infinity.
1375      *
1376      * <li>If the argument is zero, then the result is {@code 1.0}.
1377      *
1378      * </ul>
1379      *
1380      * @param   x The number whose hyperbolic cosine is to be returned.
1381      * @return  The hyperbolic cosine of {@code x}.
1382      * @since 1.5
1383      */
1384     public static native double cosh(double x);
1385 
1386     /**
1387      * Returns the hyperbolic tangent of a {@code double} value.
1388      * The hyperbolic tangent of <i>x</i> is defined to be
1389      * (<i>e<sup>x</sup>&nbsp;-&nbsp;e<sup>-x</sup></i>)/(<i>e<sup>x</sup>&nbsp;+&nbsp;e<sup>-x</sup></i>),
1390      * in other words, {@linkplain Math#sinh
1391      * sinh(<i>x</i>)}/{@linkplain Math#cosh cosh(<i>x</i>)}.  Note
1392      * that the absolute value of the exact tanh is always less than
1393      * 1.
1394      *
1395      * <p>Special cases:
1396      * <ul>
1397      *
1398      * <li>If the argument is NaN, then the result is NaN.
1399      *
1400      * <li>If the argument is zero, then the result is a zero with the
1401      * same sign as the argument.
1402      *
1403      * <li>If the argument is positive infinity, then the result is
1404      * {@code +1.0}.
1405      *
1406      * <li>If the argument is negative infinity, then the result is
1407      * {@code -1.0}.
1408      *
1409      * </ul>
1410      *
1411      * @param   x The number whose hyperbolic tangent is to be returned.
1412      * @return  The hyperbolic tangent of {@code x}.
1413      * @since 1.5
1414      */
1415     public static native double tanh(double x);
1416 
1417     /**
1418      * Returns sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)
1419      * without intermediate overflow or underflow.
1420      *
1421      * <p>Special cases:
1422      * <ul>
1423      *
1424      * <li> If either argument is infinite, then the result
1425      * is positive infinity.
1426      *
1427      * <li> If either argument is NaN and neither argument is infinite,
1428      * then the result is NaN.
1429      *
1430      * </ul>
1431      *
1432      * @param x a value
1433      * @param y a value
1434      * @return sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)
1435      * without intermediate overflow or underflow
1436      * @since 1.5
1437      */
1438     public static double hypot(double x, double y) {
1439         return FdLibm.Hypot.compute(x, y);
1440     }
1441 
1442     /**
1443      * Returns <i>e</i><sup>x</sup>&nbsp;-1.  Note that for values of
1444      * <i>x</i> near 0, the exact sum of
1445      * {@code expm1(x)}&nbsp;+&nbsp;1 is much closer to the true
1446      * result of <i>e</i><sup>x</sup> than {@code exp(x)}.
1447      *
1448      * <p>Special cases:
1449      * <ul>
1450      * <li>If the argument is NaN, the result is NaN.
1451      *
1452      * <li>If the argument is positive infinity, then the result is
1453      * positive infinity.
1454      *
1455      * <li>If the argument is negative infinity, then the result is
1456      * -1.0.
1457      *
1458      * <li>If the argument is zero, then the result is a zero with the
1459      * same sign as the argument.
1460      *
1461      * </ul>
1462      *
1463      * @param   x   the exponent to raise <i>e</i> to in the computation of
1464      *              <i>e</i><sup>{@code x}</sup>&nbsp;-1.
1465      * @return  the value <i>e</i><sup>{@code x}</sup>&nbsp;-&nbsp;1.
1466      * @since 1.5
1467      */
1468     public static native double expm1(double x);
1469 
1470     /**
1471      * Returns the natural logarithm of the sum of the argument and 1.
1472      * Note that for small values {@code x}, the result of
1473      * {@code log1p(x)} is much closer to the true result of ln(1
1474      * + {@code x}) than the floating-point evaluation of
1475      * {@code log(1.0+x)}.
1476      *
1477      * <p>Special cases:
1478      * <ul>
1479      *
1480      * <li>If the argument is NaN or less than -1, then the result is
1481      * NaN.
1482      *
1483      * <li>If the argument is positive infinity, then the result is
1484      * positive infinity.
1485      *
1486      * <li>If the argument is negative one, then the result is
1487      * negative infinity.
1488      *
1489      * <li>If the argument is zero, then the result is a zero with the
1490      * same sign as the argument.
1491      *
1492      * </ul>
1493      *
1494      * @param   x   a value
1495      * @return the value ln({@code x}&nbsp;+&nbsp;1), the natural
1496      * log of {@code x}&nbsp;+&nbsp;1
1497      * @since 1.5
1498      */
1499     public static native double log1p(double x);
1500 
1501     /**
1502      * Returns the first floating-point argument with the sign of the
1503      * second floating-point argument.  For this method, a NaN
1504      * {@code sign} argument is always treated as if it were
1505      * positive.
1506      *
1507      * @param magnitude  the parameter providing the magnitude of the result
1508      * @param sign   the parameter providing the sign of the result
1509      * @return a value with the magnitude of {@code magnitude}
1510      * and the sign of {@code sign}.
1511      * @since 1.6
1512      */
1513     public static double copySign(double magnitude, double sign) {
1514         return Math.copySign(magnitude, (Double.isNaN(sign)?1.0d:sign));
1515     }
1516 
1517     /**
1518      * Returns the first floating-point argument with the sign of the
1519      * second floating-point argument.  For this method, a NaN
1520      * {@code sign} argument is always treated as if it were
1521      * positive.
1522      *
1523      * @param magnitude  the parameter providing the magnitude of the result
1524      * @param sign   the parameter providing the sign of the result
1525      * @return a value with the magnitude of {@code magnitude}
1526      * and the sign of {@code sign}.
1527      * @since 1.6
1528      */
1529     public static float copySign(float magnitude, float sign) {
1530         return Math.copySign(magnitude, (Float.isNaN(sign)?1.0f:sign));
1531     }
1532     /**
1533      * Returns the unbiased exponent used in the representation of a
1534      * {@code float}.  Special cases:
1535      *
1536      * <ul>
1537      * <li>If the argument is NaN or infinite, then the result is
1538      * {@link Float#MAX_EXPONENT} + 1.
1539      * <li>If the argument is zero or subnormal, then the result is
1540      * {@link Float#MIN_EXPONENT} -1.
1541      * </ul>
1542      * @param f a {@code float} value
1543      * @return the unbiased exponent of the argument
1544      * @since 1.6
1545      */
1546     public static int getExponent(float f) {
1547         return Math.getExponent(f);
1548     }
1549 
1550     /**
1551      * Returns the unbiased exponent used in the representation of a
1552      * {@code double}.  Special cases:
1553      *
1554      * <ul>
1555      * <li>If the argument is NaN or infinite, then the result is
1556      * {@link Double#MAX_EXPONENT} + 1.
1557      * <li>If the argument is zero or subnormal, then the result is
1558      * {@link Double#MIN_EXPONENT} -1.
1559      * </ul>
1560      * @param d a {@code double} value
1561      * @return the unbiased exponent of the argument
1562      * @since 1.6
1563      */
1564     public static int getExponent(double d) {
1565         return Math.getExponent(d);
1566     }
1567 
1568     /**
1569      * Returns the floating-point number adjacent to the first
1570      * argument in the direction of the second argument.  If both
1571      * arguments compare as equal the second argument is returned.
1572      *
1573      * <p>Special cases:
1574      * <ul>
1575      * <li> If either argument is a NaN, then NaN is returned.
1576      *
1577      * <li> If both arguments are signed zeros, {@code direction}
1578      * is returned unchanged (as implied by the requirement of
1579      * returning the second argument if the arguments compare as
1580      * equal).
1581      *
1582      * <li> If {@code start} is
1583      * &plusmn;{@link Double#MIN_VALUE} and {@code direction}
1584      * has a value such that the result should have a smaller
1585      * magnitude, then a zero with the same sign as {@code start}
1586      * is returned.
1587      *
1588      * <li> If {@code start} is infinite and
1589      * {@code direction} has a value such that the result should
1590      * have a smaller magnitude, {@link Double#MAX_VALUE} with the
1591      * same sign as {@code start} is returned.
1592      *
1593      * <li> If {@code start} is equal to &plusmn;
1594      * {@link Double#MAX_VALUE} and {@code direction} has a
1595      * value such that the result should have a larger magnitude, an
1596      * infinity with same sign as {@code start} is returned.
1597      * </ul>
1598      *
1599      * @param start  starting floating-point value
1600      * @param direction value indicating which of
1601      * {@code start}'s neighbors or {@code start} should
1602      * be returned
1603      * @return The floating-point number adjacent to {@code start} in the
1604      * direction of {@code direction}.
1605      * @since 1.6
1606      */
1607     public static double nextAfter(double start, double direction) {
1608         return Math.nextAfter(start, direction);
1609     }
1610 
1611     /**
1612      * Returns the floating-point number adjacent to the first
1613      * argument in the direction of the second argument.  If both
1614      * arguments compare as equal a value equivalent to the second argument
1615      * is returned.
1616      *
1617      * <p>Special cases:
1618      * <ul>
1619      * <li> If either argument is a NaN, then NaN is returned.
1620      *
1621      * <li> If both arguments are signed zeros, a value equivalent
1622      * to {@code direction} is returned.
1623      *
1624      * <li> If {@code start} is
1625      * &plusmn;{@link Float#MIN_VALUE} and {@code direction}
1626      * has a value such that the result should have a smaller
1627      * magnitude, then a zero with the same sign as {@code start}
1628      * is returned.
1629      *
1630      * <li> If {@code start} is infinite and
1631      * {@code direction} has a value such that the result should
1632      * have a smaller magnitude, {@link Float#MAX_VALUE} with the
1633      * same sign as {@code start} is returned.
1634      *
1635      * <li> If {@code start} is equal to &plusmn;
1636      * {@link Float#MAX_VALUE} and {@code direction} has a
1637      * value such that the result should have a larger magnitude, an
1638      * infinity with same sign as {@code start} is returned.
1639      * </ul>
1640      *
1641      * @param start  starting floating-point value
1642      * @param direction value indicating which of
1643      * {@code start}'s neighbors or {@code start} should
1644      * be returned
1645      * @return The floating-point number adjacent to {@code start} in the
1646      * direction of {@code direction}.
1647      * @since 1.6
1648      */
1649     public static float nextAfter(float start, double direction) {
1650         return Math.nextAfter(start, direction);
1651     }
1652 
1653     /**
1654      * Returns the floating-point value adjacent to {@code d} in
1655      * the direction of positive infinity.  This method is
1656      * semantically equivalent to {@code nextAfter(d,
1657      * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
1658      * implementation may run faster than its equivalent
1659      * {@code nextAfter} call.
1660      *
1661      * <p>Special Cases:
1662      * <ul>
1663      * <li> If the argument is NaN, the result is NaN.
1664      *
1665      * <li> If the argument is positive infinity, the result is
1666      * positive infinity.
1667      *
1668      * <li> If the argument is zero, the result is
1669      * {@link Double#MIN_VALUE}
1670      *
1671      * </ul>
1672      *
1673      * @param d starting floating-point value
1674      * @return The adjacent floating-point value closer to positive
1675      * infinity.
1676      * @since 1.6
1677      */
1678     public static double nextUp(double d) {
1679         return Math.nextUp(d);
1680     }
1681 
1682     /**
1683      * Returns the floating-point value adjacent to {@code f} in
1684      * the direction of positive infinity.  This method is
1685      * semantically equivalent to {@code nextAfter(f,
1686      * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
1687      * implementation may run faster than its equivalent
1688      * {@code nextAfter} call.
1689      *
1690      * <p>Special Cases:
1691      * <ul>
1692      * <li> If the argument is NaN, the result is NaN.
1693      *
1694      * <li> If the argument is positive infinity, the result is
1695      * positive infinity.
1696      *
1697      * <li> If the argument is zero, the result is
1698      * {@link Float#MIN_VALUE}
1699      *
1700      * </ul>
1701      *
1702      * @param f starting floating-point value
1703      * @return The adjacent floating-point value closer to positive
1704      * infinity.
1705      * @since 1.6
1706      */
1707     public static float nextUp(float f) {
1708         return Math.nextUp(f);
1709     }
1710 
1711     /**
1712      * Returns the floating-point value adjacent to {@code d} in
1713      * the direction of negative infinity.  This method is
1714      * semantically equivalent to {@code nextAfter(d,
1715      * Double.NEGATIVE_INFINITY)}; however, a
1716      * {@code nextDown} implementation may run faster than its
1717      * equivalent {@code nextAfter} call.
1718      *
1719      * <p>Special Cases:
1720      * <ul>
1721      * <li> If the argument is NaN, the result is NaN.
1722      *
1723      * <li> If the argument is negative infinity, the result is
1724      * negative infinity.
1725      *
1726      * <li> If the argument is zero, the result is
1727      * {@code -Double.MIN_VALUE}
1728      *
1729      * </ul>
1730      *
1731      * @param d  starting floating-point value
1732      * @return The adjacent floating-point value closer to negative
1733      * infinity.
1734      * @since 1.8
1735      */
1736     public static double nextDown(double d) {
1737         return Math.nextDown(d);
1738     }
1739 
1740     /**
1741      * Returns the floating-point value adjacent to {@code f} in
1742      * the direction of negative infinity.  This method is
1743      * semantically equivalent to {@code nextAfter(f,
1744      * Float.NEGATIVE_INFINITY)}; however, a
1745      * {@code nextDown} implementation may run faster than its
1746      * equivalent {@code nextAfter} call.
1747      *
1748      * <p>Special Cases:
1749      * <ul>
1750      * <li> If the argument is NaN, the result is NaN.
1751      *
1752      * <li> If the argument is negative infinity, the result is
1753      * negative infinity.
1754      *
1755      * <li> If the argument is zero, the result is
1756      * {@code -Float.MIN_VALUE}
1757      *
1758      * </ul>
1759      *
1760      * @param f  starting floating-point value
1761      * @return The adjacent floating-point value closer to negative
1762      * infinity.
1763      * @since 1.8
1764      */
1765     public static float nextDown(float f) {
1766         return Math.nextDown(f);
1767     }
1768 
1769     /**
1770      * Returns {@code d} &times;
1771      * 2<sup>{@code scaleFactor}</sup> rounded as if performed
1772      * by a single correctly rounded floating-point multiply to a
1773      * member of the double value set.  See the Java
1774      * Language Specification for a discussion of floating-point
1775      * value sets.  If the exponent of the result is between {@link
1776      * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
1777      * answer is calculated exactly.  If the exponent of the result
1778      * would be larger than {@code Double.MAX_EXPONENT}, an
1779      * infinity is returned.  Note that if the result is subnormal,
1780      * precision may be lost; that is, when {@code scalb(x, n)}
1781      * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
1782      * <i>x</i>.  When the result is non-NaN, the result has the same
1783      * sign as {@code d}.
1784      *
1785      * <p>Special cases:
1786      * <ul>
1787      * <li> If the first argument is NaN, NaN is returned.
1788      * <li> If the first argument is infinite, then an infinity of the
1789      * same sign is returned.
1790      * <li> If the first argument is zero, then a zero of the same
1791      * sign is returned.
1792      * </ul>
1793      *
1794      * @param d number to be scaled by a power of two.
1795      * @param scaleFactor power of 2 used to scale {@code d}
1796      * @return {@code d} &times; 2<sup>{@code scaleFactor}</sup>
1797      * @since 1.6
1798      */
1799     public static double scalb(double d, int scaleFactor) {
1800         return Math.scalb(d, scaleFactor);
1801     }
1802 
1803     /**
1804      * Returns {@code f} &times;
1805      * 2<sup>{@code scaleFactor}</sup> rounded as if performed
1806      * by a single correctly rounded floating-point multiply to a
1807      * member of the float value set.  See the Java
1808      * Language Specification for a discussion of floating-point
1809      * value sets.  If the exponent of the result is between {@link
1810      * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
1811      * answer is calculated exactly.  If the exponent of the result
1812      * would be larger than {@code Float.MAX_EXPONENT}, an
1813      * infinity is returned.  Note that if the result is subnormal,
1814      * precision may be lost; that is, when {@code scalb(x, n)}
1815      * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
1816      * <i>x</i>.  When the result is non-NaN, the result has the same
1817      * sign as {@code f}.
1818      *
1819      * <p>Special cases:
1820      * <ul>
1821      * <li> If the first argument is NaN, NaN is returned.
1822      * <li> If the first argument is infinite, then an infinity of the
1823      * same sign is returned.
1824      * <li> If the first argument is zero, then a zero of the same
1825      * sign is returned.
1826      * </ul>
1827      *
1828      * @param f number to be scaled by a power of two.
1829      * @param scaleFactor power of 2 used to scale {@code f}
1830      * @return {@code f} &times; 2<sup>{@code scaleFactor}</sup>
1831      * @since 1.6
1832      */
1833     public static float scalb(float f, int scaleFactor) {
1834         return Math.scalb(f, scaleFactor);
1835     }
1836 }