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