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