151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski/*
2e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * This code is free software; you can redistribute it and/or modify it
651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * under the terms of the GNU General Public License version 2 only, as
751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * published by the Free Software Foundation.  Oracle designates this
851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * particular file as subject to the "Classpath" exception as provided
951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * by Oracle in the LICENSE file that accompanied this code.
1051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
1151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * This code is distributed in the hope that it will be useful, but WITHOUT
1251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * version 2 for more details (a copy is included in the LICENSE file that
1551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * accompanied this code).
1651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
1751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * You should have received a copy of the GNU General Public License version
1851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 2 along with this work; if not, write to the Free Software Foundation,
1951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
2151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * or visit www.oracle.com if you need additional information or have any
2351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * questions.
2451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */
2551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
2651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskipackage java.lang;
2751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskiimport java.util.Random;
2851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskiimport sun.misc.DoubleConsts;
2951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
3051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski/**
3151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * The class {@code StrictMath} contains methods for performing basic
3251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * numeric operations such as the elementary exponential, logarithm,
3351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * square root, and trigonometric functions.
3451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
3551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>To help ensure portability of Java programs, the definitions of
3651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * some of the numeric functions in this package require that they
3751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * produce the same results as certain published algorithms. These
3851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * algorithms are available from the well-known network library
3951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code netlib} as the package "Freely Distributable Math
4051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Library," <a
4151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * href="ftp://ftp.netlib.org/fdlibm.tar">{@code fdlibm}</a>. These
4251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * algorithms, which are written in the C programming language, are
4351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * then to be understood as executed with all floating-point
4451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * operations following the rules of Java floating-point arithmetic.
4551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
4651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>The Java math library is defined with respect to
4751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code fdlibm} version 5.3. Where {@code fdlibm} provides
4851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * more than one definition for a function (such as
4951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code acos}), use the "IEEE 754 core function" version
5051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * (residing in a file whose name begins with the letter
5151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code e}).  The methods which require {@code fdlibm}
5251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * semantics are {@code sin}, {@code cos}, {@code tan},
5351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code asin}, {@code acos}, {@code atan},
5451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code exp}, {@code log}, {@code log10},
5551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code cbrt}, {@code atan2}, {@code pow},
5651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code sinh}, {@code cosh}, {@code tanh},
5751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@code hypot}, {@code expm1}, and {@code log1p}.
5851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
596a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak * <p>
606a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak * The platform uses signed two's complement integer arithmetic with
616a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak * int and long primitive types.  The developer should choose
626a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak * the primitive type to ensure that arithmetic operations consistently
636a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak * produce correct results, which in some cases means the operations
646a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak * will not overflow the range of values of the computation.
656a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak * The best practice is to choose the primitive type and algorithm to avoid
666a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak * overflow. In cases where the size is {@code int} or {@code long} and
676a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak * overflow errors need to be detected, the methods {@code addExact},
686a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak * {@code subtractExact}, {@code multiplyExact}, and {@code toIntExact}
696a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak * throw an {@code ArithmeticException} when the results overflow.
706a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak * For other arithmetic operations such as divide, absolute value,
716a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak * increment, decrement, and negation overflow occurs only with
726a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak * a specific minimum or maximum value and should be checked against
736a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak * the minimum or maximum as appropriate.
746a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak *
7551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @author  unascribed
7651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @author  Joseph D. Darcy
7751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @since   1.3
7851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */
7951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
8051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskipublic final class StrictMath {
8151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
8251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
8351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Don't let anyone instantiate this class.
8451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
8551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    private StrictMath() {}
8651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
8751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
8851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * The {@code double} value that is closer than any other to
8951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <i>e</i>, the base of the natural logarithms.
9051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
9151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static final double E = 2.7182818284590452354;
9251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
9351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
9451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * The {@code double} value that is closer than any other to
9551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <i>pi</i>, the ratio of the circumference of a circle to its
9651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * diameter.
9751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
9851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static final double PI = 3.14159265358979323846;
9951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
10051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
10151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the trigonometric sine of an angle. Special cases:
10251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument is NaN or an infinity, then the
10351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is NaN.
10451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is zero, then the result is a zero with the
10551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * same sign as the argument.</ul>
10651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
10751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   an angle, in radians.
10851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the sine of the argument.
10951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
11051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double sin(double a);
11151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
11251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
11351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the trigonometric cosine of an angle. Special cases:
11451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument is NaN or an infinity, then the
11551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is NaN.</ul>
11651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
11751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   an angle, in radians.
11851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the cosine of the argument.
11951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
12051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double cos(double a);
12151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
12251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
12351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the trigonometric tangent of an angle. Special cases:
12451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument is NaN or an infinity, then the result
12551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is NaN.
12651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is zero, then the result is a zero with the
12751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * same sign as the argument.</ul>
12851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
12951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   an angle, in radians.
13051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the tangent of the argument.
13151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
13251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double tan(double a);
13351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
13451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
13551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the arc sine of a value; the returned angle is in the
13651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
13751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument is NaN or its absolute value is greater
13851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * than 1, then the result is NaN.
13951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is zero, then the result is a zero with the
14051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * same sign as the argument.</ul>
14151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
14251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   the value whose arc sine is to be returned.
14351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the arc sine of the argument.
14451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
14551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double asin(double a);
14651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
14751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
14851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the arc cosine of a value; the returned angle is in the
14951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * range 0.0 through <i>pi</i>.  Special case:
15051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument is NaN or its absolute value is greater
15151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * than 1, then the result is NaN.</ul>
15251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
15351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   the value whose arc cosine is to be returned.
15451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the arc cosine of the argument.
15551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
15651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double acos(double a);
15751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
15851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
15951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the arc tangent of a value; the returned angle is in the
16051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
16151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument is NaN, then the result is NaN.
16251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is zero, then the result is a zero with the
16351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * same sign as the argument.</ul>
16451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
16551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   the value whose arc tangent is to be returned.
16651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the arc tangent of the argument.
16751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
16851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double atan(double a);
16951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
17051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
17151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Converts an angle measured in degrees to an approximately
17251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * equivalent angle measured in radians.  The conversion from
17351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * degrees to radians is generally inexact.
17451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
17551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   angdeg   an angle, in degrees
17651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the measurement of the angle {@code angdeg}
17751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          in radians.
17851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
17951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static strictfp double toRadians(double angdeg) {
1806a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        // Do not delegate to Math.toRadians(angdeg) because
1816a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        // this method has the strictfp modifier.
18251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        return angdeg / 180.0 * PI;
18351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
18451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
18551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
18651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Converts an angle measured in radians to an approximately
18751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * equivalent angle measured in degrees.  The conversion from
18851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * radians to degrees is generally inexact; users should
18951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <i>not</i> expect {@code cos(toRadians(90.0))} to exactly
19051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * equal {@code 0.0}.
19151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
19251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   angrad   an angle, in radians
19351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the measurement of the angle {@code angrad}
19451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          in degrees.
19551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
19651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static strictfp double toDegrees(double angrad) {
1976a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        // Do not delegate to Math.toDegrees(angrad) because
1986a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        // this method has the strictfp modifier.
19951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        return angrad * 180.0 / PI;
20051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
20151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
20251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
20351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns Euler's number <i>e</i> raised to the power of a
20451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code double} value. Special cases:
20551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument is NaN, the result is NaN.
20651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is positive infinity, then the result is
20751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * positive infinity.
20851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is negative infinity, then the result is
20951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * positive zero.</ul>
21051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
21151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   the exponent to raise <i>e</i> to.
21251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the value <i>e</i><sup>{@code a}</sup>,
21351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          where <i>e</i> is the base of the natural logarithms.
21451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
21551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double exp(double a);
21651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
21751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
21851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the natural logarithm (base <i>e</i>) of a {@code double}
21951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value. Special cases:
22051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument is NaN or less than zero, then the result
22151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is NaN.
22251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is positive infinity, then the result is
22351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * positive infinity.
22451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is positive zero or negative zero, then the
22551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is negative infinity.</ul>
22651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
22751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   a value
22851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the value ln&nbsp;{@code a}, the natural logarithm of
22951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          {@code a}.
23051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
23151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double log(double a);
23251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
23351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
23451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
23551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the base 10 logarithm of a {@code double} value.
23651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Special cases:
23751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
23851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument is NaN or less than zero, then the result
23951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is NaN.
24051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is positive infinity, then the result is
24151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * positive infinity.
24251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is positive zero or negative zero, then the
24351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is negative infinity.
24451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is equal to 10<sup><i>n</i></sup> for
24551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * integer <i>n</i>, then the result is <i>n</i>.
24651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
24751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
24851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   a value
24951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the base 10 logarithm of  {@code a}.
25051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.5
25151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
25251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double log10(double a);
25351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
25451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
25551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the correctly rounded positive square root of a
25651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code double} value.
25751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Special cases:
25851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument is NaN or less than zero, then the result
25951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is NaN.
26051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is positive infinity, then the result is positive
26151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * infinity.
26251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is positive zero or negative zero, then the
26351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is the same as the argument.</ul>
26451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Otherwise, the result is the {@code double} value closest to
26551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the true mathematical square root of the argument value.
26651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
26751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   a value.
26851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the positive square root of {@code a}.
26951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
27051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double sqrt(double a);
27151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
27251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
27351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the cube root of a {@code double} value.  For
27451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * positive finite {@code x}, {@code cbrt(-x) ==
27551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * -cbrt(x)}; that is, the cube root of a negative value is
27651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the negative of the cube root of that value's magnitude.
27751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Special cases:
27851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
27951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
28051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
28151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is NaN, then the result is NaN.
28251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
28351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is infinite, then the result is an infinity
28451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * with the same sign as the argument.
28551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
28651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is zero, then the result is a zero with the
28751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * same sign as the argument.
28851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
28951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
29051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
29151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   a value.
29251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the cube root of {@code a}.
29351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.5
29451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
29551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double cbrt(double a);
29651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
29751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
29851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Computes the remainder operation on two arguments as prescribed
29951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * by the IEEE 754 standard.
30051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * The remainder value is mathematically equal to
30151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <code>f1&nbsp;-&nbsp;f2</code>&nbsp;&times;&nbsp;<i>n</i>,
30251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * where <i>n</i> is the mathematical integer closest to the exact
30351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * mathematical value of the quotient {@code f1/f2}, and if two
30451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * mathematical integers are equally close to {@code f1/f2},
30551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * then <i>n</i> is the integer that is even. If the remainder is
30651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * zero, its sign is the same as the sign of the first argument.
30751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Special cases:
30851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If either argument is NaN, or the first argument is infinite,
30951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * or the second argument is positive zero or negative zero, then the
31051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is NaN.
31151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the first argument is finite and the second argument is
31251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * infinite, then the result is the same as the first argument.</ul>
31351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
31451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   f1   the dividend.
31551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   f2   the divisor.
31651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the remainder when {@code f1} is divided by
31751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          {@code f2}.
31851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
31951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double IEEEremainder(double f1, double f2);
32051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
32151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
32251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the smallest (closest to negative infinity)
32351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code double} value that is greater than or equal to the
32451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument and is equal to a mathematical integer. Special cases:
32551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument value is already equal to a
32651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * mathematical integer, then the result is the same as the
32751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument.  <li>If the argument is NaN or an infinity or
32851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * positive zero or negative zero, then the result is the same as
32951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the argument.  <li>If the argument value is less than zero but
33051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * greater than -1.0, then the result is negative zero.</ul> Note
33151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * that the value of {@code StrictMath.ceil(x)} is exactly the
33251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value of {@code -StrictMath.floor(-x)}.
33351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
33451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   a value.
33551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the smallest (closest to negative infinity)
33651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          floating-point value that is greater than or equal to
33751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          the argument and is equal to a mathematical integer.
33851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
33951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static double ceil(double a) {
34051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        return floorOrCeil(a, -0.0, 1.0, 1.0);
34151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
34251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
34351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
34451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the largest (closest to positive infinity)
34551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code double} value that is less than or equal to the
34651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument and is equal to a mathematical integer. Special cases:
34751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument value is already equal to a
34851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * mathematical integer, then the result is the same as the
34951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument.  <li>If the argument is NaN or an infinity or
35051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * positive zero or negative zero, then the result is the same as
35151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the argument.</ul>
35251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
35351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   a value.
35451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the largest (closest to positive infinity)
35551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          floating-point value that less than or equal to the argument
35651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          and is equal to a mathematical integer.
35751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
35851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static double floor(double a) {
35951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        return floorOrCeil(a, -1.0, 0.0, -1.0);
36051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
36151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
36251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
36351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Internal method to share logic between floor and ceil.
36451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
36551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param a the value to be floored or ceiled
36651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param negativeBoundary result for values in (-1, 0)
36751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param positiveBoundary result for values in (0, 1)
36851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param increment value to add when the argument is non-integral
36951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
37051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    private static double floorOrCeil(double a,
37151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski                                      double negativeBoundary,
37251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski                                      double positiveBoundary,
37351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski                                      double sign) {
37451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        int exponent = Math.getExponent(a);
37551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
37651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        if (exponent < 0) {
37751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            /*
37851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski             * Absolute value of argument is less than 1.
37951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski             * floorOrceil(-0.0) => -0.0
38051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski             * floorOrceil(+0.0) => +0.0
38151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski             */
38251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            return ((a == 0.0) ? a :
38351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski                    ( (a < 0.0) ?  negativeBoundary : positiveBoundary) );
38451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        } else if (exponent >= 52) {
38551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            /*
38651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski             * Infinity, NaN, or a value so large it must be integral.
38751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski             */
38851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            return a;
38951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        }
39051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        // Else the argument is either an integral value already XOR it
39151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        // has to be rounded to one.
39251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        assert exponent >= 0 && exponent <= 51;
39351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
39451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        long doppel = Double.doubleToRawLongBits(a);
39551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        long mask   = DoubleConsts.SIGNIF_BIT_MASK >> exponent;
39651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
39751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        if ( (mask & doppel) == 0L )
39851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            return a; // integral value
39951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        else {
40051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            double result = Double.longBitsToDouble(doppel & (~mask));
40151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            if (sign*a > 0.0)
40251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski                result = result + sign;
40351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            return result;
40451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        }
40551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
40651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
40751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
40851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the {@code double} value that is closest in value
40951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * to the argument and is equal to a mathematical integer. If two
41051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code double} values that are mathematical integers are
41151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * equally close to the value of the argument, the result is the
41251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * integer value that is even. Special cases:
41351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument value is already equal to a mathematical
41451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * integer, then the result is the same as the argument.
41551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is NaN or an infinity or positive zero or negative
41651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * zero, then the result is the same as the argument.</ul>
41751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
41851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   a value.
41951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the closest floating-point value to {@code a} that is
42051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          equal to a mathematical integer.
42151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @author Joseph D. Darcy
42251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
42351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static double rint(double a) {
42451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        /*
42551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * If the absolute value of a is not less than 2^52, it
42651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * is either a finite integer (the double format does not have
42751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * enough significand bits for a number that large to have any
42851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * fractional portion), an infinity, or a NaN.  In any of
42951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * these cases, rint of the argument is the argument.
43051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         *
43151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * Otherwise, the sum (twoToThe52 + a ) will properly round
43251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * away any fractional portion of a since ulp(twoToThe52) ==
43351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * 1.0; subtracting out twoToThe52 from this sum will then be
43451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * exact and leave the rounded integer portion of a.
43551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         *
43651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * This method does *not* need to be declared strictfp to get
43751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * fully reproducible results.  Whether or not a method is
43851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * declared strictfp can only make a difference in the
43951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * returned result if some operation would overflow or
44051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * underflow with strictfp semantics.  The operation
44151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * (twoToThe52 + a ) cannot overflow since large values of a
44251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * are screened out; the add cannot underflow since twoToThe52
44351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * is too large.  The subtraction ((twoToThe52 + a ) -
44451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * twoToThe52) will be exact as discussed above and thus
44551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * cannot overflow or meaningfully underflow.  Finally, the
44651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * last multiply in the return statement is by plus or minus
44751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         * 1.0, which is exact too.
44851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski         */
44951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        double twoToThe52 = (double)(1L << 52); // 2^52
4506a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        double sign = Math.copySign(1.0, a); // preserve sign info
45151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        a = Math.abs(a);
45251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
45351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        if (a < twoToThe52) { // E_min <= ilogb(a) <= 51
45451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            a = ((twoToThe52 + a ) - twoToThe52);
45551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        }
45651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
45751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        return sign * a; // restore original sign
45851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
45951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
46051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
46151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the angle <i>theta</i> from the conversion of rectangular
46251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * coordinates ({@code x},&nbsp;{@code y}) to polar
46351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * coordinates (r,&nbsp;<i>theta</i>).
46451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * This method computes the phase <i>theta</i> by computing an arc tangent
46551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * of {@code y/x} in the range of -<i>pi</i> to <i>pi</i>. Special
46651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * cases:
46751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If either argument is NaN, then the result is NaN.
46851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the first argument is positive zero and the second argument
46951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is positive, or the first argument is positive and finite and the
47051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * second argument is positive infinity, then the result is positive
47151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * zero.
47251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the first argument is negative zero and the second argument
47351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is positive, or the first argument is negative and finite and the
47451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * second argument is positive infinity, then the result is negative zero.
47551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the first argument is positive zero and the second argument
47651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is negative, or the first argument is positive and finite and the
47751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * second argument is negative infinity, then the result is the
47851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code double} value closest to <i>pi</i>.
47951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the first argument is negative zero and the second argument
48051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is negative, or the first argument is negative and finite and the
48151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * second argument is negative infinity, then the result is the
48251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code double} value closest to -<i>pi</i>.
48351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the first argument is positive and the second argument is
48451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * positive zero or negative zero, or the first argument is positive
48551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * infinity and the second argument is finite, then the result is the
48651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code double} value closest to <i>pi</i>/2.
48751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the first argument is negative and the second argument is
48851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * positive zero or negative zero, or the first argument is negative
48951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * infinity and the second argument is finite, then the result is the
49051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code double} value closest to -<i>pi</i>/2.
49151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If both arguments are positive infinity, then the result is the
49251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code double} value closest to <i>pi</i>/4.
49351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the first argument is positive infinity and the second argument
49451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is negative infinity, then the result is the {@code double}
49551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value closest to 3*<i>pi</i>/4.
49651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the first argument is negative infinity and the second argument
49751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is positive infinity, then the result is the {@code double} value
49851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * closest to -<i>pi</i>/4.
49951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If both arguments are negative infinity, then the result is the
50051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code double} value closest to -3*<i>pi</i>/4.</ul>
50151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
50251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   y   the ordinate coordinate
50351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   x   the abscissa coordinate
50451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the <i>theta</i> component of the point
50551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          (<i>r</i>,&nbsp;<i>theta</i>)
50651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          in polar coordinates that corresponds to the point
50751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          (<i>x</i>,&nbsp;<i>y</i>) in Cartesian coordinates.
50851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
50951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double atan2(double y, double x);
51051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
51151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
51251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
51351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the value of the first argument raised to the power of the
51451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * second argument. Special cases:
51551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
51651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the second argument is positive or negative zero, then the
51751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is 1.0.
51851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the second argument is 1.0, then the result is the same as the
51951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * first argument.
52051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the second argument is NaN, then the result is NaN.
52151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the first argument is NaN and the second argument is nonzero,
52251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * then the result is NaN.
52351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
52451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If
52551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
52651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the absolute value of the first argument is greater than 1
52751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * and the second argument is positive infinity, or
52851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the absolute value of the first argument is less than 1 and
52951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the second argument is negative infinity,
53051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
53151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * then the result is positive infinity.
53251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
53351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If
53451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
53551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the absolute value of the first argument is greater than 1 and
53651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the second argument is negative infinity, or
53751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the absolute value of the
53851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * first argument is less than 1 and the second argument is positive
53951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * infinity,
54051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
54151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * then the result is positive zero.
54251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
54351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the absolute value of the first argument equals 1 and the
54451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * second argument is infinite, then the result is NaN.
54551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
54651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If
54751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
54851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the first argument is positive zero and the second argument
54951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is greater than zero, or
55051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the first argument is positive infinity and the second
55151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument is less than zero,
55251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
55351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * then the result is positive zero.
55451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
55551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If
55651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
55751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the first argument is positive zero and the second argument
55851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is less than zero, or
55951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the first argument is positive infinity and the second
56051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument is greater than zero,
56151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
56251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * then the result is positive infinity.
56351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
56451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If
56551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
56651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the first argument is negative zero and the second argument
56751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is greater than zero but not a finite odd integer, or
56851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the first argument is negative infinity and the second
56951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument is less than zero but not a finite odd integer,
57051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
57151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * then the result is positive zero.
57251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
57351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If
57451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
57551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the first argument is negative zero and the second argument
57651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is a positive finite odd integer, or
57751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the first argument is negative infinity and the second
57851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument is a negative finite odd integer,
57951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
58051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * then the result is negative zero.
58151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
58251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If
58351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
58451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the first argument is negative zero and the second argument
58551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is less than zero but not a finite odd integer, or
58651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the first argument is negative infinity and the second
58751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument is greater than zero but not a finite odd integer,
58851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
58951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * then the result is positive infinity.
59051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
59151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If
59251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
59351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the first argument is negative zero and the second argument
59451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is a negative finite odd integer, or
59551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>the first argument is negative infinity and the second
59651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument is a positive finite odd integer,
59751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
59851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * then the result is negative infinity.
59951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
60051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the first argument is finite and less than zero
60151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
60251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> if the second argument is a finite even integer, the
60351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is equal to the result of raising the absolute value of
60451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the first argument to the power of the second argument
60551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
60651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>if the second argument is a finite odd integer, the result
60751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is equal to the negative of the result of raising the absolute
60851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value of the first argument to the power of the second
60951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument
61051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
61151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>if the second argument is finite and not an integer, then
61251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the result is NaN.
61351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
61451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
61551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If both arguments are integers, then the result is exactly equal
61651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * to the mathematical result of raising the first argument to the power
61751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * of the second argument if that result can in fact be represented
61851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * exactly as a {@code double} value.</ul>
61951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
62051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>(In the foregoing descriptions, a floating-point value is
62151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * considered to be an integer if and only if it is finite and a
62251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * fixed point of the method {@link #ceil ceil} or,
62351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * equivalently, a fixed point of the method {@link #floor
62451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * floor}. A value is a fixed point of a one-argument
62551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * method if and only if the result of applying the method to the
62651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value is equal to the value.)
62751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
62851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   base.
62951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   b   the exponent.
63051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the value {@code a}<sup>{@code b}</sup>.
63151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
63251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double pow(double a, double b);
63351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
63451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
63551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the closest {@code int} to the argument, with ties
636f043756ef5140e633d6b7afc9ae1f0058c9fa70fHans Boehm     * rounding to positive infinity.
63751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
63851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special cases:
63951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument is NaN, the result is 0.
64051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is negative infinity or any value less than or
64151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * equal to the value of {@code Integer.MIN_VALUE}, the result is
64251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * equal to the value of {@code Integer.MIN_VALUE}.
64351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is positive infinity or any value greater than or
64451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * equal to the value of {@code Integer.MAX_VALUE}, the result is
64551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * equal to the value of {@code Integer.MAX_VALUE}.</ul>
64651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
64751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   a floating-point value to be rounded to an integer.
64851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the value of the argument rounded to the nearest
64951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          {@code int} value.
65051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @see     java.lang.Integer#MAX_VALUE
65151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @see     java.lang.Integer#MIN_VALUE
65251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
65351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static int round(float a) {
65451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        return Math.round(a);
65551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
65651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
65751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
65851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the closest {@code long} to the argument, with ties
659f043756ef5140e633d6b7afc9ae1f0058c9fa70fHans Boehm     * rounding to positive infinity.
66051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
66151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special cases:
66251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument is NaN, the result is 0.
66351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is negative infinity or any value less than or
66451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * equal to the value of {@code Long.MIN_VALUE}, the result is
66551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * equal to the value of {@code Long.MIN_VALUE}.
66651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is positive infinity or any value greater than or
66751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * equal to the value of {@code Long.MAX_VALUE}, the result is
66851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * equal to the value of {@code Long.MAX_VALUE}.</ul>
66951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
67051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a  a floating-point value to be rounded to a
67151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          {@code long}.
67251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the value of the argument rounded to the nearest
67351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          {@code long} value.
67451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @see     java.lang.Long#MAX_VALUE
67551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @see     java.lang.Long#MIN_VALUE
67651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
67751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static long round(double a) {
67851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        return Math.round(a);
67951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
68051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
6816a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak    private static final class RandomNumberGeneratorHolder {
6826a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        static final Random randomNumberGenerator = new Random();
68351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
68451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
68551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
68651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns a {@code double} value with a positive sign, greater
68751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * than or equal to {@code 0.0} and less than {@code 1.0}.
68851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returned values are chosen pseudorandomly with (approximately)
68951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * uniform distribution from that range.
69051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
69151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>When this method is first called, it creates a single new
69251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * pseudorandom-number generator, exactly as if by the expression
69351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
69451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <blockquote>{@code new java.util.Random()}</blockquote>
69551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
69651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * This new pseudorandom-number generator is used thereafter for
69751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * all calls to this method and is used nowhere else.
69851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
69951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>This method is properly synchronized to allow correct use by
70051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * more than one thread. However, if many threads need to generate
70151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * pseudorandom numbers at a great rate, it may reduce contention
7026a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * for each thread to have its own pseudorandom-number generator.
70351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
70451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  a pseudorandom {@code double} greater than or equal
70551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * to {@code 0.0} and less than {@code 1.0}.
70651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @see Random#nextDouble()
70751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
70851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static double random() {
7096a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return RandomNumberGeneratorHolder.randomNumberGenerator.nextDouble();
71051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
71151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
71251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
713e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * Returns the sum of its arguments,
714e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * throwing an exception if the result overflows an {@code int}.
715e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
716e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param x the first value
717e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param y the second value
718e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @return the result
719e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @throws ArithmeticException if the result overflows an int
720e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @see Math#addExact(int,int)
721e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @since 1.8
722e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     */
723e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    public static int addExact(int x, int y) {
724e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong        return Math.addExact(x, y);
725e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    }
726e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong
727e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    /**
728e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * Returns the sum of its arguments,
729e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * throwing an exception if the result overflows a {@code long}.
730e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
731e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param x the first value
732e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param y the second value
733e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @return the result
734e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @throws ArithmeticException if the result overflows a long
735e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @see Math#addExact(long,long)
736e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @since 1.8
737e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     */
738e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    public static long addExact(long x, long y) {
739e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong        return Math.addExact(x, y);
740e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    }
741e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong
742e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    /**
743e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * Returns the difference of the arguments,
744e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * throwing an exception if the result overflows an {@code int}.
745e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
746e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param x the first value
747e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param y the second value to subtract from the first
748e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @return the result
749e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @throws ArithmeticException if the result overflows an int
750e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @see Math#subtractExact(int,int)
751e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @since 1.8
752e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     */
753e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    public static int subtractExact(int x, int y) {
754e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong        return Math.subtractExact(x, y);
755e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    }
756e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong
757e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    /**
758e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * Returns the difference of the arguments,
759e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * throwing an exception if the result overflows a {@code long}.
760e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
761e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param x the first value
762e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param y the second value to subtract from the first
763e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @return the result
764e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @throws ArithmeticException if the result overflows a long
765e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @see Math#subtractExact(long,long)
766e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @since 1.8
767e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     */
768e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    public static long subtractExact(long x, long y) {
769e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong        return Math.subtractExact(x, y);
770e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    }
771e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong
772e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    /**
773e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * Returns the product of the arguments,
774e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * throwing an exception if the result overflows an {@code int}.
775e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
776e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param x the first value
777e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param y the second value
778e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @return the result
779e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @throws ArithmeticException if the result overflows an int
780e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @see Math#multiplyExact(int,int)
781e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @since 1.8
782e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     */
783e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    public static int multiplyExact(int x, int y) {
784e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong        return Math.multiplyExact(x, y);
785e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    }
786e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong
787e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    /**
788e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * Returns the product of the arguments,
789e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * throwing an exception if the result overflows a {@code long}.
790e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
791e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param x the first value
792e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param y the second value
793e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @return the result
794e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @throws ArithmeticException if the result overflows a long
795e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @see Math#multiplyExact(long,long)
796e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @since 1.8
797e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     */
798e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    public static long multiplyExact(long x, long y) {
799e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong        return Math.multiplyExact(x, y);
800e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    }
801e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong
802e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    /**
803e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * Returns the value of the {@code long} argument;
804e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * throwing an exception if the value overflows an {@code int}.
805e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
806e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param value the long value
807e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @return the argument as an int
808e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @throws ArithmeticException if the {@code argument} overflows an int
809e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @see Math#toIntExact(long)
810e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @since 1.8
811e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     */
812e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    public static int toIntExact(long value) {
813e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong        return Math.toIntExact(value);
814e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    }
815e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong
816e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    /**
817e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * Returns the largest (closest to positive infinity)
818e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * {@code int} value that is less than or equal to the algebraic quotient.
819e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * There is one special case, if the dividend is the
820e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * {@linkplain Integer#MIN_VALUE Integer.MIN_VALUE} and the divisor is {@code -1},
821e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * then integer overflow occurs and
822e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * the result is equal to the {@code Integer.MIN_VALUE}.
823e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <p>
824e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * See {@link Math#floorDiv(int, int) Math.floorDiv} for examples and
825e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * a comparison to the integer division {@code /} operator.
826e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
827e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param x the dividend
828e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param y the divisor
829e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @return the largest (closest to positive infinity)
830e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * {@code int} value that is less than or equal to the algebraic quotient.
831e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @throws ArithmeticException if the divisor {@code y} is zero
832e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @see Math#floorDiv(int, int)
833e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @see Math#floor(double)
834e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @since 1.8
835e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     */
836e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    public static int floorDiv(int x, int y) {
837e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong        return Math.floorDiv(x, y);
838e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    }
839e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong
840e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    /**
841e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * Returns the largest (closest to positive infinity)
842e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * {@code long} value that is less than or equal to the algebraic quotient.
843e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * There is one special case, if the dividend is the
844e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * {@linkplain Long#MIN_VALUE Long.MIN_VALUE} and the divisor is {@code -1},
845e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * then integer overflow occurs and
846e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * the result is equal to the {@code Long.MIN_VALUE}.
847e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <p>
848e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * See {@link Math#floorDiv(int, int) Math.floorDiv} for examples and
849e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * a comparison to the integer division {@code /} operator.
850e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
851e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param x the dividend
852e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param y the divisor
853e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @return the largest (closest to positive infinity)
854e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * {@code long} value that is less than or equal to the algebraic quotient.
855e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @throws ArithmeticException if the divisor {@code y} is zero
856e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @see Math#floorDiv(long, long)
857e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @see Math#floor(double)
858e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @since 1.8
859e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     */
860e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    public static long floorDiv(long x, long y) {
861e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong        return Math.floorDiv(x, y);
862e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    }
863e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong
864e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    /**
865e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * Returns the floor modulus of the {@code int} arguments.
866e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <p>
867e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * The floor modulus is {@code x - (floorDiv(x, y) * y)},
868e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * has the same sign as the divisor {@code y}, and
869e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * is in the range of {@code -abs(y) < r < +abs(y)}.
870e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <p>
871e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * The relationship between {@code floorDiv} and {@code floorMod} is such that:
872e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <ul>
873e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *   <li>{@code floorDiv(x, y) * y + floorMod(x, y) == x}
874e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * </ul>
875e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <p>
876e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * See {@link Math#floorMod(int, int) Math.floorMod} for examples and
877e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * a comparison to the {@code %} operator.
878e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
879e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param x the dividend
880e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param y the divisor
881e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @return the floor modulus {@code x - (floorDiv(x, y) * y)}
882e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @throws ArithmeticException if the divisor {@code y} is zero
883e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @see Math#floorMod(int, int)
884e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @see StrictMath#floorDiv(int, int)
885e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @since 1.8
886e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     */
887e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    public static int floorMod(int x, int y) {
888e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong        return Math.floorMod(x , y);
889e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    }
890e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    /**
891e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * Returns the floor modulus of the {@code long} arguments.
892e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <p>
893e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * The floor modulus is {@code x - (floorDiv(x, y) * y)},
894e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * has the same sign as the divisor {@code y}, and
895e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * is in the range of {@code -abs(y) < r < +abs(y)}.
896e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <p>
897e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * The relationship between {@code floorDiv} and {@code floorMod} is such that:
898e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <ul>
899e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *   <li>{@code floorDiv(x, y) * y + floorMod(x, y) == x}
900e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * </ul>
901e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <p>
902e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * See {@link Math#floorMod(int, int) Math.floorMod} for examples and
903e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * a comparison to the {@code %} operator.
904e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
905e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param x the dividend
906e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param y the divisor
907e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @return the floor modulus {@code x - (floorDiv(x, y) * y)}
908e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @throws ArithmeticException if the divisor {@code y} is zero
909e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @see Math#floorMod(long, long)
910e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @see StrictMath#floorDiv(long, long)
911e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @since 1.8
912e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     */
913e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    public static long floorMod(long x, long y) {
914e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong        return Math.floorMod(x, y);
915e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    }
916e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong
917e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    /**
9186a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * Returns the absolute value of an {@code int} value.
91951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * If the argument is not negative, the argument is returned.
92051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * If the argument is negative, the negation of the argument is returned.
92151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
92251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Note that if the argument is equal to the value of
92351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@link Integer#MIN_VALUE}, the most negative representable
92451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code int} value, the result is that same value, which is
92551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * negative.
92651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
92751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   the  argument whose absolute value is to be determined.
92851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the absolute value of the argument.
92951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
93051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static int abs(int a) {
9316a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.abs(a);
93251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
93351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
93451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
93551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the absolute value of a {@code long} value.
93651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * If the argument is not negative, the argument is returned.
93751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * If the argument is negative, the negation of the argument is returned.
93851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
93951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Note that if the argument is equal to the value of
94051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@link Long#MIN_VALUE}, the most negative representable
94151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code long} value, the result is that same value, which
94251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is negative.
94351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
94451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   the  argument whose absolute value is to be determined.
94551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the absolute value of the argument.
94651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
94751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static long abs(long a) {
9486a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.abs(a);
94951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
95051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
95151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
95251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the absolute value of a {@code float} value.
95351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * If the argument is not negative, the argument is returned.
95451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * If the argument is negative, the negation of the argument is returned.
95551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Special cases:
95651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument is positive zero or negative zero, the
95751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is positive zero.
95851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is infinite, the result is positive infinity.
95951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is NaN, the result is NaN.</ul>
96051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * In other words, the result is the same as the value of the expression:
96151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>{@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
96251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
96351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   the argument whose absolute value is to be determined
96451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the absolute value of the argument.
96551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
96651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static float abs(float a) {
9676a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.abs(a);
96851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
96951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
97051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
97151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the absolute value of a {@code double} value.
97251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * If the argument is not negative, the argument is returned.
97351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * If the argument is negative, the negation of the argument is returned.
97451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Special cases:
97551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul><li>If the argument is positive zero or negative zero, the result
97651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is positive zero.
97751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is infinite, the result is positive infinity.
97851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is NaN, the result is NaN.</ul>
97951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * In other words, the result is the same as the value of the expression:
98051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>{@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
98151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
98251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   the argument whose absolute value is to be determined
98351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the absolute value of the argument.
98451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
98551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static double abs(double a) {
9866a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.abs(a);
98751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
98851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
98951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
99051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the greater of two {@code int} values. That is, the
99151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is the argument closer to the value of
99251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@link Integer#MAX_VALUE}. If the arguments have the same value,
99351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the result is that same value.
99451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
99551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   an argument.
99651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   b   another argument.
99751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the larger of {@code a} and {@code b}.
99851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
99951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static int max(int a, int b) {
10006a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.max(a, b);
100151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
100251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
100351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
100451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the greater of two {@code long} values. That is, the
100551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is the argument closer to the value of
100651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@link Long#MAX_VALUE}. If the arguments have the same value,
100751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the result is that same value.
100851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
100951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   an argument.
101051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   b   another argument.
101151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the larger of {@code a} and {@code b}.
101251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        */
101351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static long max(long a, long b) {
10146a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.max(a, b);
101551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
101651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
101751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
101851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the greater of two {@code float} values.  That is,
101951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the result is the argument closer to positive infinity. If the
102051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * arguments have the same value, the result is that same
102151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value. If either value is NaN, then the result is NaN.  Unlike
102251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the numerical comparison operators, this method considers
102351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * negative zero to be strictly smaller than positive zero. If one
102451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument is positive zero and the other negative zero, the
102551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is positive zero.
102651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
102751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   an argument.
102851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   b   another argument.
102951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the larger of {@code a} and {@code b}.
103051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
103151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static float max(float a, float b) {
10326a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.max(a, b);
103351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
103451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
103551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
103651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the greater of two {@code double} values.  That
103751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is, the result is the argument closer to positive infinity. If
103851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the arguments have the same value, the result is that same
103951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value. If either value is NaN, then the result is NaN.  Unlike
104051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the numerical comparison operators, this method considers
104151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * negative zero to be strictly smaller than positive zero. If one
104251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument is positive zero and the other negative zero, the
104351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is positive zero.
104451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
104551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   an argument.
104651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   b   another argument.
104751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the larger of {@code a} and {@code b}.
104851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
104951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static double max(double a, double b) {
10506a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.max(a, b);
105151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
105251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
105351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
105451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the smaller of two {@code int} values. That is,
105551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the result the argument closer to the value of
105651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@link Integer#MIN_VALUE}.  If the arguments have the same
105751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value, the result is that same value.
105851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
105951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   an argument.
106051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   b   another argument.
106151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the smaller of {@code a} and {@code b}.
106251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
106351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static int min(int a, int b) {
10646a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.min(a, b);
106551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
106651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
106751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
106851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the smaller of two {@code long} values. That is,
106951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the result is the argument closer to the value of
107051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@link Long#MIN_VALUE}. If the arguments have the same
107151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value, the result is that same value.
107251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
107351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   an argument.
107451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   b   another argument.
107551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the smaller of {@code a} and {@code b}.
107651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
107751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static long min(long a, long b) {
10786a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.min(a, b);
107951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
108051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
108151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
108251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the smaller of two {@code float} values.  That is,
108351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the result is the value closer to negative infinity. If the
108451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * arguments have the same value, the result is that same
108551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value. If either value is NaN, then the result is NaN.  Unlike
108651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the numerical comparison operators, this method considers
108751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * negative zero to be strictly smaller than positive zero.  If
108851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * one argument is positive zero and the other is negative zero,
108951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the result is negative zero.
109051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
109151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   an argument.
109251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   b   another argument.
109351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the smaller of {@code a} and {@code b.}
109451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
109551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static float min(float a, float b) {
10966a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.min(a, b);
109751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
109851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
109951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
110051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the smaller of two {@code double} values.  That
110151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is, the result is the value closer to negative infinity. If the
110251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * arguments have the same value, the result is that same
110351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value. If either value is NaN, then the result is NaN.  Unlike
110451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the numerical comparison operators, this method considers
110551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * negative zero to be strictly smaller than positive zero. If one
110651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument is positive zero and the other is negative zero, the
110751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is negative zero.
110851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
110951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   a   an argument.
111051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   b   another argument.
111151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the smaller of {@code a} and {@code b}.
111251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
111351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static double min(double a, double b) {
11146a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.min(a, b);
111551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
111651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
111751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
11186a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * Returns the size of an ulp of the argument.  An ulp, unit in
11196a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * the last place, of a {@code double} value is the positive
11206a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * distance between this floating-point value and the {@code
11216a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * double} value next larger in magnitude.  Note that for non-NaN
11226a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * <i>x</i>, <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
112351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
112451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special Cases:
112551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
112651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is NaN, then the result is NaN.
112751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is positive or negative infinity, then the
112851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is positive infinity.
112951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is positive or negative zero, then the result is
113051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code Double.MIN_VALUE}.
113151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is &plusmn;{@code Double.MAX_VALUE}, then
113251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the result is equal to 2<sup>971</sup>.
113351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
113451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
113551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param d the floating-point value whose ulp is to be returned
113651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return the size of an ulp of the argument
113751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @author Joseph D. Darcy
113851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.5
113951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
114051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static double ulp(double d) {
11416a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.ulp(d);
114251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
114351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
114451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
11456a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * Returns the size of an ulp of the argument.  An ulp, unit in
11466a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * the last place, of a {@code float} value is the positive
11476a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * distance between this floating-point value and the {@code
11486a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * float} value next larger in magnitude.  Note that for non-NaN
11496a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * <i>x</i>, <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
115051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
115151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special Cases:
115251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
115351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is NaN, then the result is NaN.
115451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is positive or negative infinity, then the
115551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result is positive infinity.
115651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is positive or negative zero, then the result is
115751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code Float.MIN_VALUE}.
115851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is &plusmn;{@code Float.MAX_VALUE}, then
115951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the result is equal to 2<sup>104</sup>.
116051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
116151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
116251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param f the floating-point value whose ulp is to be returned
116351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return the size of an ulp of the argument
116451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @author Joseph D. Darcy
116551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.5
116651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
116751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static float ulp(float f) {
11686a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.ulp(f);
116951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
117051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
117151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
117251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the signum function of the argument; zero if the argument
117351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is zero, 1.0 if the argument is greater than zero, -1.0 if the
117451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument is less than zero.
117551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
117651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special Cases:
117751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
117851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is NaN, then the result is NaN.
117951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is positive zero or negative zero, then the
118051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *      result is the same as the argument.
118151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
118251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
118351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param d the floating-point value whose signum is to be returned
118451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return the signum function of the argument
118551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @author Joseph D. Darcy
118651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.5
118751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
118851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static double signum(double d) {
11896a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.signum(d);
119051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
119151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
119251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
119351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the signum function of the argument; zero if the argument
119451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is zero, 1.0f if the argument is greater than zero, -1.0f if the
119551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument is less than zero.
119651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
119751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special Cases:
119851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
119951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is NaN, then the result is NaN.
120051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is positive zero or negative zero, then the
120151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *      result is the same as the argument.
120251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
120351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
120451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param f the floating-point value whose signum is to be returned
120551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return the signum function of the argument
120651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @author Joseph D. Darcy
120751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.5
120851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
120951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static float signum(float f) {
12106a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.signum(f);
121151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
121251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
121351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
121451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the hyperbolic sine of a {@code double} value.
121551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * The hyperbolic sine of <i>x</i> is defined to be
121651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * (<i>e<sup>x</sup>&nbsp;-&nbsp;e<sup>-x</sup></i>)/2
121751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * where <i>e</i> is {@linkplain Math#E Euler's number}.
121851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
121951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special cases:
122051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
122151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
122251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is NaN, then the result is NaN.
122351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
122451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is infinite, then the result is an infinity
122551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * with the same sign as the argument.
122651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
122751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is zero, then the result is a zero with the
122851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * same sign as the argument.
122951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
123051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
123151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
123251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   x The number whose hyperbolic sine is to be returned.
123351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  The hyperbolic sine of {@code x}.
123451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.5
123551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
123651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double sinh(double x);
123751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
123851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
123951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the hyperbolic cosine of a {@code double} value.
124051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * The hyperbolic cosine of <i>x</i> is defined to be
124151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * (<i>e<sup>x</sup>&nbsp;+&nbsp;e<sup>-x</sup></i>)/2
124251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * where <i>e</i> is {@linkplain Math#E Euler's number}.
124351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
124451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special cases:
124551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
124651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
124751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is NaN, then the result is NaN.
124851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
124951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is infinite, then the result is positive
125051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * infinity.
125151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
125251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is zero, then the result is {@code 1.0}.
125351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
125451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
125551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
125651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   x The number whose hyperbolic cosine is to be returned.
125751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  The hyperbolic cosine of {@code x}.
125851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.5
125951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
126051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double cosh(double x);
126151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
126251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
126351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the hyperbolic tangent of a {@code double} value.
126451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * The hyperbolic tangent of <i>x</i> is defined to be
126551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * (<i>e<sup>x</sup>&nbsp;-&nbsp;e<sup>-x</sup></i>)/(<i>e<sup>x</sup>&nbsp;+&nbsp;e<sup>-x</sup></i>),
126651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * in other words, {@linkplain Math#sinh
126751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * sinh(<i>x</i>)}/{@linkplain Math#cosh cosh(<i>x</i>)}.  Note
126851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * that the absolute value of the exact tanh is always less than
126951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * 1.
127051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
127151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special cases:
127251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
127351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
127451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is NaN, then the result is NaN.
127551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
127651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is zero, then the result is a zero with the
127751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * same sign as the argument.
127851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
127951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is positive infinity, then the result is
128051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code +1.0}.
128151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
128251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is negative infinity, then the result is
128351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code -1.0}.
128451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
128551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
128651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
128751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   x The number whose hyperbolic tangent is to be returned.
128851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  The hyperbolic tangent of {@code x}.
128951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.5
129051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
129151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double tanh(double x);
129251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
129351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
129451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)
129551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * without intermediate overflow or underflow.
129651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
129751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special cases:
129851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
129951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
130051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If either argument is infinite, then the result
130151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is positive infinity.
130251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
130351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If either argument is NaN and neither argument is infinite,
130451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * then the result is NaN.
130551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
130651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
130751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
130851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param x a value
130951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param y a value
131051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)
131151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * without intermediate overflow or underflow
131251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.5
131351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
131451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double hypot(double x, double y);
131551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
131651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
131751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns <i>e</i><sup>x</sup>&nbsp;-1.  Note that for values of
131851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <i>x</i> near 0, the exact sum of
131951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code expm1(x)}&nbsp;+&nbsp;1 is much closer to the true
132051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * result of <i>e</i><sup>x</sup> than {@code exp(x)}.
132151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
132251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special cases:
132351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
132451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is NaN, the result is NaN.
132551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
132651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is positive infinity, then the result is
132751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * positive infinity.
132851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
132951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is negative infinity, then the result is
133051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * -1.0.
133151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
133251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is zero, then the result is a zero with the
133351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * same sign as the argument.
133451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
133551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
133651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
133751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   x   the exponent to raise <i>e</i> to in the computation of
133851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *              <i>e</i><sup>{@code x}</sup>&nbsp;-1.
133951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return  the value <i>e</i><sup>{@code x}</sup>&nbsp;-&nbsp;1.
134051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.5
134151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
134251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double expm1(double x);
134351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
134451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
134551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the natural logarithm of the sum of the argument and 1.
134651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Note that for small values {@code x}, the result of
134751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code log1p(x)} is much closer to the true result of ln(1
134851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * + {@code x}) than the floating-point evaluation of
134951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code log(1.0+x)}.
135051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
135151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special cases:
135251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
135351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
135451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is NaN or less than -1, then the result is
135551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * NaN.
135651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
135751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is positive infinity, then the result is
135851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * positive infinity.
135951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
136051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is negative one, then the result is
136151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * negative infinity.
136251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
136351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is zero, then the result is a zero with the
136451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * same sign as the argument.
136551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
136651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
136751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
136851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param   x   a value
136951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return the value ln({@code x}&nbsp;+&nbsp;1), the natural
137051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * log of {@code x}&nbsp;+&nbsp;1
137151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.5
137251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
137351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static native double log1p(double x);
137451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
137551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
137651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the first floating-point argument with the sign of the
137751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * second floating-point argument.  For this method, a NaN
137851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code sign} argument is always treated as if it were
137951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * positive.
138051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
138151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param magnitude  the parameter providing the magnitude of the result
138251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param sign   the parameter providing the sign of the result
138351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return a value with the magnitude of {@code magnitude}
138451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * and the sign of {@code sign}.
138551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.6
138651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
138751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static double copySign(double magnitude, double sign) {
13886a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.copySign(magnitude, (Double.isNaN(sign)?1.0d:sign));
138951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
139051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
139151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
139251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the first floating-point argument with the sign of the
139351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * second floating-point argument.  For this method, a NaN
139451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code sign} argument is always treated as if it were
139551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * positive.
139651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
139751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param magnitude  the parameter providing the magnitude of the result
139851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param sign   the parameter providing the sign of the result
139951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return a value with the magnitude of {@code magnitude}
140051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * and the sign of {@code sign}.
140151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.6
140251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
140351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static float copySign(float magnitude, float sign) {
14046a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.copySign(magnitude, (Float.isNaN(sign)?1.0f:sign));
140551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
140651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
140751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the unbiased exponent used in the representation of a
140851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code float}.  Special cases:
140951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
141051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
141151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is NaN or infinite, then the result is
141251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@link Float#MAX_EXPONENT} + 1.
141351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is zero or subnormal, then the result is
141451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@link Float#MIN_EXPONENT} -1.
141551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
141651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param f a {@code float} value
14176a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * @return the unbiased exponent of the argument
141851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.6
141951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
142051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static int getExponent(float f) {
14216a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.getExponent(f);
142251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
142351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
142451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
142551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the unbiased exponent used in the representation of a
142651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code double}.  Special cases:
142751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
142851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
142951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is NaN or infinite, then the result is
143051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@link Double#MAX_EXPONENT} + 1.
143151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li>If the argument is zero or subnormal, then the result is
143251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@link Double#MIN_EXPONENT} -1.
143351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
143451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param d a {@code double} value
14356a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * @return the unbiased exponent of the argument
143651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.6
143751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
143851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static int getExponent(double d) {
14396a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.getExponent(d);
144051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
144151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
144251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
144351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the floating-point number adjacent to the first
144451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument in the direction of the second argument.  If both
144551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * arguments compare as equal the second argument is returned.
144651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
144751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special cases:
144851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
144951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If either argument is a NaN, then NaN is returned.
145051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
145151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If both arguments are signed zeros, {@code direction}
145251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is returned unchanged (as implied by the requirement of
145351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * returning the second argument if the arguments compare as
145451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * equal).
145551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
145651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If {@code start} is
145751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * &plusmn;{@link Double#MIN_VALUE} and {@code direction}
145851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * has a value such that the result should have a smaller
145951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * magnitude, then a zero with the same sign as {@code start}
146051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is returned.
146151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
146251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If {@code start} is infinite and
146351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code direction} has a value such that the result should
146451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * have a smaller magnitude, {@link Double#MAX_VALUE} with the
146551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * same sign as {@code start} is returned.
146651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
146751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If {@code start} is equal to &plusmn;
146851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@link Double#MAX_VALUE} and {@code direction} has a
146951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value such that the result should have a larger magnitude, an
147051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * infinity with same sign as {@code start} is returned.
147151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
147251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
147351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param start  starting floating-point value
147451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param direction value indicating which of
147551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code start}'s neighbors or {@code start} should
147651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * be returned
147751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return The floating-point number adjacent to {@code start} in the
147851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * direction of {@code direction}.
147951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.6
148051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
148151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static double nextAfter(double start, double direction) {
14826a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.nextAfter(start, direction);
148351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
148451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
148551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
148651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the floating-point number adjacent to the first
148751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * argument in the direction of the second argument.  If both
148851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * arguments compare as equal a value equivalent to the second argument
148951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is returned.
149051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
149151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special cases:
149251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
149351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If either argument is a NaN, then NaN is returned.
149451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
149551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If both arguments are signed zeros, a value equivalent
149651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * to {@code direction} is returned.
149751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
149851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If {@code start} is
149951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * &plusmn;{@link Float#MIN_VALUE} and {@code direction}
150051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * has a value such that the result should have a smaller
150151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * magnitude, then a zero with the same sign as {@code start}
150251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is returned.
150351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
150451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If {@code start} is infinite and
150551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code direction} has a value such that the result should
150651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * have a smaller magnitude, {@link Float#MAX_VALUE} with the
150751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * same sign as {@code start} is returned.
150851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
150951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If {@code start} is equal to &plusmn;
151051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@link Float#MAX_VALUE} and {@code direction} has a
151151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value such that the result should have a larger magnitude, an
151251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * infinity with same sign as {@code start} is returned.
151351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
151451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
151551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param start  starting floating-point value
151651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param direction value indicating which of
151751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code start}'s neighbors or {@code start} should
151851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * be returned
151951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return The floating-point number adjacent to {@code start} in the
152051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * direction of {@code direction}.
152151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.6
152251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
152351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static float nextAfter(float start, double direction) {
15246a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.nextAfter(start, direction);
152551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
152651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
152751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
152851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the floating-point value adjacent to {@code d} in
152951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the direction of positive infinity.  This method is
153051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * semantically equivalent to {@code nextAfter(d,
153151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
153251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * implementation may run faster than its equivalent
153351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code nextAfter} call.
153451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
153551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special Cases:
153651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
153751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is NaN, the result is NaN.
153851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
153951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is positive infinity, the result is
154051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * positive infinity.
154151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
154251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is zero, the result is
154351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@link Double#MIN_VALUE}
154451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
154551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
154651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
154751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param d starting floating-point value
154851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return The adjacent floating-point value closer to positive
154951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * infinity.
155051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.6
155151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
155251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static double nextUp(double d) {
15536a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.nextUp(d);
155451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
155551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
155651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
155751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Returns the floating-point value adjacent to {@code f} in
155851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the direction of positive infinity.  This method is
155951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * semantically equivalent to {@code nextAfter(f,
156051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
156151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * implementation may run faster than its equivalent
156251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@code nextAfter} call.
156351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
156451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special Cases:
156551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
156651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is NaN, the result is NaN.
156751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
156851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is positive infinity, the result is
156951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * positive infinity.
157051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
157151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the argument is zero, the result is
157251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * {@link Float#MIN_VALUE}
157351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
157451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
157551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
157651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param f starting floating-point value
157751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return The adjacent floating-point value closer to positive
157851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * infinity.
157951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.6
158051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
158151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static float nextUp(float f) {
15826a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.nextUp(f);
158351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
158451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
1585e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    /**
1586e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * Returns the floating-point value adjacent to {@code d} in
1587e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * the direction of negative infinity.  This method is
1588e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * semantically equivalent to {@code nextAfter(d,
1589e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * Double.NEGATIVE_INFINITY)}; however, a
1590e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * {@code nextDown} implementation may run faster than its
1591e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * equivalent {@code nextAfter} call.
1592e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
1593e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <p>Special Cases:
1594e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <ul>
1595e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <li> If the argument is NaN, the result is NaN.
1596e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
1597e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <li> If the argument is negative infinity, the result is
1598e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * negative infinity.
1599e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
1600e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <li> If the argument is zero, the result is
1601e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * {@code -Double.MIN_VALUE}
1602e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
1603e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * </ul>
1604e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
1605e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param d  starting floating-point value
1606e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @return The adjacent floating-point value closer to negative
1607e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * infinity.
1608e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @since 1.8
1609e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     */
1610e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    public static double nextDown(double d) {
1611e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong        return Math.nextDown(d);
1612e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    }
1613e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong
1614e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    /**
1615e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * Returns the floating-point value adjacent to {@code f} in
1616e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * the direction of negative infinity.  This method is
1617e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * semantically equivalent to {@code nextAfter(f,
1618e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * Float.NEGATIVE_INFINITY)}; however, a
1619e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * {@code nextDown} implementation may run faster than its
1620e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * equivalent {@code nextAfter} call.
1621e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
1622e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <p>Special Cases:
1623e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <ul>
1624e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <li> If the argument is NaN, the result is NaN.
1625e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
1626e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <li> If the argument is negative infinity, the result is
1627e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * negative infinity.
1628e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
1629e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * <li> If the argument is zero, the result is
1630e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * {@code -Float.MIN_VALUE}
1631e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
1632e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * </ul>
1633e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     *
1634e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @param f  starting floating-point value
1635e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @return The adjacent floating-point value closer to negative
1636e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * infinity.
1637e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     * @since 1.8
1638e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong     */
1639e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    public static float nextDown(float f) {
1640e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong        return Math.nextDown(f);
1641e9d9ae3d5e57a60e20c2c01e3dceb3e51de8b9f4Yi Kong    }
164251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
164351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
16446a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * Returns {@code d} &times;
164551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
164651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * by a single correctly rounded floating-point multiply to a
164751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * member of the double value set.  See the Java
164851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Language Specification for a discussion of floating-point
164951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value sets.  If the exponent of the result is between {@link
165051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
165151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * answer is calculated exactly.  If the exponent of the result
165251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * would be larger than {@code Double.MAX_EXPONENT}, an
165351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * infinity is returned.  Note that if the result is subnormal,
165451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * precision may be lost; that is, when {@code scalb(x, n)}
165551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
165651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <i>x</i>.  When the result is non-NaN, the result has the same
165751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * sign as {@code d}.
165851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
165951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special cases:
166051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
166151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the first argument is NaN, NaN is returned.
166251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the first argument is infinite, then an infinity of the
166351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * same sign is returned.
166451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the first argument is zero, then a zero of the same
166551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * sign is returned.
166651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
166751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
166851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param d number to be scaled by a power of two.
166951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param scaleFactor power of 2 used to scale {@code d}
167051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return {@code d} &times; 2<sup>{@code scaleFactor}</sup>
167151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.6
167251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
167351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static double scalb(double d, int scaleFactor) {
16746a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.scalb(d, scaleFactor);
167551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
167651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
167751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
16786a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak     * Returns {@code f} &times;
167951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
168051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * by a single correctly rounded floating-point multiply to a
168151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * member of the float value set.  See the Java
168251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Language Specification for a discussion of floating-point
168351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * value sets.  If the exponent of the result is between {@link
168451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
168551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * answer is calculated exactly.  If the exponent of the result
168651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * would be larger than {@code Float.MAX_EXPONENT}, an
168751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * infinity is returned.  Note that if the result is subnormal,
168851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * precision may be lost; that is, when {@code scalb(x, n)}
168951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
169051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <i>x</i>.  When the result is non-NaN, the result has the same
169151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * sign as {@code f}.
169251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
169351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>Special cases:
169451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <ul>
169551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the first argument is NaN, NaN is returned.
169651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the first argument is infinite, then an infinity of the
169751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * same sign is returned.
169851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <li> If the first argument is zero, then a zero of the same
169951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * sign is returned.
170051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </ul>
170151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
170251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param f number to be scaled by a power of two.
170351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param scaleFactor power of 2 used to scale {@code f}
170451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @return {@code f} &times; 2<sup>{@code scaleFactor}</sup>
170551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @since 1.6
170651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
170751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static float scalb(float f, int scaleFactor) {
17086a5351e12a69e865fe31b8aac989bd2573aebbcaPrzemyslaw Szczepaniak        return Math.scalb(f, scaleFactor);
170951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
171051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski}
1711