jdk/src/share/classes/java/lang/Math.java
author darcy
Sun, 17 Jul 2011 18:53:40 -0700
changeset 10122 bf8e763fcceb
parent 9269 f66626469aa8
child 10598 efd29b4b3e67
permissions -rw-r--r--
7062430: Minor inconsistency in ulp descriptions Reviewed-by: smarks, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9269
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
     2
 * Copyright (c) 1994, 2011, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.Random;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * The class {@code Math} contains methods for performing basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * numeric operations such as the elementary exponential, logarithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * square root, and trigonometric functions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>Unlike some of the numeric methods of class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * {@code StrictMath}, all implementations of the equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * functions of class {@code Math} are not defined to return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * bit-for-bit same results.  This relaxation permits
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * better-performing implementations where strict reproducibility is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * not required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>By default many of the {@code Math} methods simply call
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * the equivalent method in {@code StrictMath} for their
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * implementation.  Code generators are encouraged to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * platform-specific native libraries or microprocessor instructions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * where available, to provide higher-performance implementations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * {@code Math} methods.  Such higher-performance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * implementations still must conform to the specification for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * {@code Math}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>The quality of implementation specifications concern two
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * properties, accuracy of the returned result and monotonicity of the
10122
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    53
 * method.  Accuracy of the floating-point {@code Math} methods is
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    54
 * measured in terms of <i>ulps</i>, units in the last place.  For a
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    55
 * given floating-point format, an {@linkplain #ulp(double) ulp} of a
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    56
 * specific real number value is the distance between the two
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    57
 * floating-point values bracketing that numerical value.  When
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    58
 * discussing the accuracy of a method as a whole rather than at a
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    59
 * specific argument, the number of ulps cited is for the worst-case
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    60
 * error at any argument.  If a method always has an error less than
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    61
 * 0.5 ulps, the method always returns the floating-point number
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    62
 * nearest the exact result; such a method is <i>correctly
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    63
 * rounded</i>.  A correctly rounded method is generally the best a
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    64
 * floating-point approximation can be; however, it is impractical for
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    65
 * many floating-point methods to be correctly rounded.  Instead, for
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    66
 * the {@code Math} class, a larger error bound of 1 or 2 ulps is
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    67
 * allowed for certain methods.  Informally, with a 1 ulp error bound,
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    68
 * when the exact result is a representable number, the exact result
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    69
 * should be returned as the computed result; otherwise, either of the
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    70
 * two floating-point values which bracket the exact result may be
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    71
 * returned.  For exact results large in magnitude, one of the
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    72
 * endpoints of the bracket may be infinite.  Besides accuracy at
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    73
 * individual arguments, maintaining proper relations between the
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    74
 * method at different arguments is also important.  Therefore, most
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    75
 * methods with more than 0.5 ulp errors are required to be
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    76
 * <i>semi-monotonic</i>: whenever the mathematical function is
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    77
 * non-decreasing, so is the floating-point approximation, likewise,
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    78
 * whenever the mathematical function is non-increasing, so is the
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    79
 * floating-point approximation.  Not all approximations that have 1
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
    80
 * ulp accuracy will automatically meet the monotonicity requirements.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @author  unascribed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @author  Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * @since   JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
public final class Math {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Don't let anyone instantiate this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private Math() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * The {@code double} value that is closer than any other to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * <i>e</i>, the base of the natural logarithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public static final double E = 2.7182818284590452354;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * The {@code double} value that is closer than any other to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * <i>pi</i>, the ratio of the circumference of a circle to its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * diameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public static final double PI = 3.14159265358979323846;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Returns the trigonometric sine of an angle.  Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * <ul><li>If the argument is NaN or an infinity, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * <li>If the argument is zero, then the result is a zero with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * same sign as the argument.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * <p>The computed result must be within 1 ulp of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Results must be semi-monotonic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param   a   an angle, in radians.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @return  the sine of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public static double sin(double a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return StrictMath.sin(a); // default impl. delegates to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Returns the trigonometric cosine of an angle. Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * <ul><li>If the argument is NaN or an infinity, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * result is NaN.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * <p>The computed result must be within 1 ulp of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * Results must be semi-monotonic.
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 double cos(double a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        return StrictMath.cos(a); // default impl. delegates to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Returns the trigonometric tangent of an angle.  Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * <ul><li>If the argument is NaN or an infinity, then the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * <li>If the argument is zero, then the result is a zero with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * same sign as the argument.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * <p>The computed result must be within 1 ulp of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Results must be semi-monotonic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param   a   an angle, in radians.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @return  the tangent of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public static double tan(double a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return StrictMath.tan(a); // default impl. delegates to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Returns the arc sine of a value; the returned angle is in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * <ul><li>If the argument is NaN or its absolute value is greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * than 1, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * <li>If the argument is zero, then the result is a zero with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * same sign as the argument.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * <p>The computed result must be within 1 ulp of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * Results must be semi-monotonic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @param   a   the value whose arc sine is to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * @return  the arc sine of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public static double asin(double a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        return StrictMath.asin(a); // default impl. delegates to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Returns the arc cosine of a value; the returned angle is in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * range 0.0 through <i>pi</i>.  Special case:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * <ul><li>If the argument is NaN or its absolute value is greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * than 1, then the result is NaN.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * <p>The computed result must be within 1 ulp of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Results must be semi-monotonic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param   a   the value whose arc cosine is to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @return  the arc cosine of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public static double acos(double a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        return StrictMath.acos(a); // default impl. delegates to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Returns the arc tangent of a value; the returned angle is in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * range -<i>pi</i>/2 through <i>pi</i>/2.  Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * <ul><li>If the argument is NaN, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * <li>If the argument is zero, then the result is a zero with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * same sign as the argument.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * <p>The computed result must be within 1 ulp of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Results must be semi-monotonic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param   a   the value whose arc tangent is to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @return  the arc tangent of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public static double atan(double a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return StrictMath.atan(a); // default impl. delegates to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Converts an angle measured in degrees to an approximately
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * equivalent angle measured in radians.  The conversion from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * degrees to radians is generally inexact.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @param   angdeg   an angle, in degrees
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @return  the measurement of the angle {@code angdeg}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *          in radians.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @since   1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public static double toRadians(double angdeg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return angdeg / 180.0 * PI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Converts an angle measured in radians to an approximately
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * equivalent angle measured in degrees.  The conversion from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * radians to degrees is generally inexact; users should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * <i>not</i> expect {@code cos(toRadians(90.0))} to exactly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * equal {@code 0.0}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param   angrad   an angle, in radians
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @return  the measurement of the angle {@code angrad}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *          in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @since   1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public static double toDegrees(double angrad) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return angrad * 180.0 / PI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * Returns Euler's number <i>e</i> raised to the power of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * {@code double} value.  Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * <ul><li>If the argument is NaN, the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * <li>If the argument is positive infinity, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * <li>If the argument is negative infinity, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * positive zero.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * <p>The computed result must be within 1 ulp of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Results must be semi-monotonic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @param   a   the exponent to raise <i>e</i> to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @return  the value <i>e</i><sup>{@code a}</sup>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *          where <i>e</i> is the base of the natural logarithms.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public static double exp(double a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        return StrictMath.exp(a); // default impl. delegates to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Returns the natural logarithm (base <i>e</i>) of a {@code double}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * value.  Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * <ul><li>If the argument is NaN or less than zero, then the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * <li>If the argument is positive infinity, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * <li>If the argument is positive zero or negative zero, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * result is negative infinity.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * <p>The computed result must be within 1 ulp of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Results must be semi-monotonic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @param   a   a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @return  the value ln&nbsp;{@code a}, the natural logarithm of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *          {@code a}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public static double log(double a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return StrictMath.log(a); // default impl. delegates to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * Returns the base 10 logarithm of a {@code double} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * <ul><li>If the argument is NaN or less than zero, then the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * <li>If the argument is positive infinity, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * <li>If the argument is positive zero or negative zero, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * result is negative infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * <li> If the argument is equal to 10<sup><i>n</i></sup> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * integer <i>n</i>, then the result is <i>n</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * <p>The computed result must be within 1 ulp of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Results must be semi-monotonic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @param   a   a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @return  the base 10 logarithm of  {@code a}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    public static double log10(double a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        return StrictMath.log10(a); // default impl. delegates to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Returns the correctly rounded positive square root of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * {@code double} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * <ul><li>If the argument is NaN or less than zero, then the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * <li>If the argument is positive infinity, then the result is positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * <li>If the argument is positive zero or negative zero, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * result is the same as the argument.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Otherwise, the result is the {@code double} value closest to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * the true mathematical square root of the argument value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @param   a   a value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @return  the positive square root of {@code a}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *          If the argument is NaN or less than zero, the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public static double sqrt(double a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        return StrictMath.sqrt(a); // default impl. delegates to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                                   // Note that hardware sqrt instructions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                                   // frequently can be directly used by JITs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                                   // and should be much faster than doing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                                   // Math.sqrt in software.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * Returns the cube root of a {@code double} value.  For
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * positive finite {@code x}, {@code cbrt(-x) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * -cbrt(x)}; that is, the cube root of a negative value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * the negative of the cube root of that value's magnitude.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * <li>If the argument is NaN, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * <li>If the argument is infinite, then the result is an infinity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * with the same sign as the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * <li>If the argument is zero, then the result is a zero with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * same sign as the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * <p>The computed result must be within 1 ulp of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @param   a   a value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @return  the cube root of {@code a}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    public static double cbrt(double a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return StrictMath.cbrt(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Computes the remainder operation on two arguments as prescribed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * by the IEEE 754 standard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * The remainder value is mathematically equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * <code>f1&nbsp;-&nbsp;f2</code>&nbsp;&times;&nbsp;<i>n</i>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * where <i>n</i> is the mathematical integer closest to the exact
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * mathematical value of the quotient {@code f1/f2}, and if two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * mathematical integers are equally close to {@code f1/f2},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * then <i>n</i> is the integer that is even. If the remainder is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * zero, its sign is the same as the sign of the first argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * <ul><li>If either argument is NaN, or the first argument is infinite,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * or the second argument is positive zero or negative zero, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * <li>If the first argument is finite and the second argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * infinite, then the result is the same as the first argument.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @param   f1   the dividend.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @param   f2   the divisor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @return  the remainder when {@code f1} is divided by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *          {@code f2}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    public static double IEEEremainder(double f1, double f2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        return StrictMath.IEEEremainder(f1, f2); // delegate to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Returns the smallest (closest to negative infinity)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * {@code double} value that is greater than or equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * argument and is equal to a mathematical integer. Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * <ul><li>If the argument value is already equal to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * mathematical integer, then the result is the same as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * argument.  <li>If the argument is NaN or an infinity or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * positive zero or negative zero, then the result is the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * the argument.  <li>If the argument value is less than zero but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * greater than -1.0, then the result is negative zero.</ul> Note
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * that the value of {@code Math.ceil(x)} is exactly the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * value of {@code -Math.floor(-x)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * @param   a   a value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @return  the smallest (closest to negative infinity)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     *          floating-point value that is greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *          the argument and is equal to a mathematical integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public static double ceil(double a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        return StrictMath.ceil(a); // default impl. delegates to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * Returns the largest (closest to positive infinity)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * {@code double} value that is less than or equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * argument and is equal to a mathematical integer. Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * <ul><li>If the argument value is already equal to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * mathematical integer, then the result is the same as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * argument.  <li>If the argument is NaN or an infinity or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * positive zero or negative zero, then the result is the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * the argument.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @param   a   a value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @return  the largest (closest to positive infinity)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *          floating-point value that less than or equal to the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *          and is equal to a mathematical integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public static double floor(double a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        return StrictMath.floor(a); // default impl. delegates to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * Returns the {@code double} value that is closest in value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * to the argument and is equal to a mathematical integer. If two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * {@code double} values that are mathematical integers are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * equally close, the result is the integer value that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * even. Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * <ul><li>If the argument value is already equal to a mathematical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * integer, then the result is the same as the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * <li>If the argument is NaN or an infinity or positive zero or negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * zero, then the result is the same as the argument.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @param   a   a {@code double} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @return  the closest floating-point value to {@code a} that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     *          equal to a mathematical integer.
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
        return StrictMath.rint(a); // default impl. delegates to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * Returns the angle <i>theta</i> from the conversion of rectangular
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * coordinates ({@code x},&nbsp;{@code y}) to polar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * coordinates (r,&nbsp;<i>theta</i>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * This method computes the phase <i>theta</i> by computing an arc tangent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * of {@code y/x} in the range of -<i>pi</i> to <i>pi</i>. Special
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * <ul><li>If either argument is NaN, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * <li>If the first argument is positive zero and the second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * is positive, or the first argument is positive and finite and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * second argument is positive infinity, then the result is positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * <li>If the first argument is negative zero and the second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * is positive, or the first argument is negative and finite and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * second argument is positive infinity, then the result is negative zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * <li>If the first argument is positive zero and the second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * is negative, or the first argument is positive and finite and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * second argument is negative infinity, then the result is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * {@code double} value closest to <i>pi</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * <li>If the first argument is negative zero and the second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * is negative, or the first argument is negative and finite and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * second argument is negative infinity, then the result is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * {@code double} value closest to -<i>pi</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * <li>If the first argument is positive and the second argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * positive zero or negative zero, or the first argument is positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * infinity and the second argument is finite, then the result is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * {@code double} value closest to <i>pi</i>/2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * <li>If the first argument is negative and the second argument is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * positive zero or negative zero, or the first argument is negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * infinity and the second argument is finite, then the result is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * {@code double} value closest to -<i>pi</i>/2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * <li>If both arguments are positive infinity, then the result is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * {@code double} value closest to <i>pi</i>/4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * <li>If the first argument is positive infinity and the second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * is negative infinity, then the result is the {@code double}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * value closest to 3*<i>pi</i>/4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * <li>If the first argument is negative infinity and the second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * is positive infinity, then the result is the {@code double} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * closest to -<i>pi</i>/4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * <li>If both arguments are negative infinity, then the result is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * {@code double} value closest to -3*<i>pi</i>/4.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * <p>The computed result must be within 2 ulps of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * Results must be semi-monotonic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @param   y   the ordinate coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @param   x   the abscissa coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @return  the <i>theta</i> component of the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *          (<i>r</i>,&nbsp;<i>theta</i>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *          in polar coordinates that corresponds to the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *          (<i>x</i>,&nbsp;<i>y</i>) in Cartesian coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public static double atan2(double y, double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        return StrictMath.atan2(y, x); // default impl. delegates to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * Returns the value of the first argument raised to the power of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * second argument. Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * <ul><li>If the second argument is positive or negative zero, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * result is 1.0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * <li>If the second argument is 1.0, then the result is the same as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * first argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * <li>If the second argument is NaN, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * <li>If the first argument is NaN and the second argument is nonzero,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * <li>If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * <li>the absolute value of the first argument is greater than 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * and the second argument is positive infinity, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * <li>the absolute value of the first argument is less than 1 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * the second argument is negative infinity,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * then the result is positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * <li>If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * <li>the absolute value of the first argument is greater than 1 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * the second argument is negative infinity, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * <li>the absolute value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * first argument is less than 1 and the second argument is positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * infinity,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * then the result is positive zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * <li>If the absolute value of the first argument equals 1 and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * second argument is infinite, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * <li>If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * <li>the first argument is positive zero and the second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * is greater than zero, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * <li>the first argument is positive infinity and the second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * argument is less than zero,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * then the result is positive zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * <li>If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * <li>the first argument is positive zero and the second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * is less than zero, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * <li>the first argument is positive infinity and the second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * argument is greater than zero,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * then the result is positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * <li>If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * <li>the first argument is negative zero and the second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * is greater than zero but not a finite odd integer, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * <li>the first argument is negative infinity and the second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * argument is less than zero but not a finite odd integer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * then the result is positive zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * <li>If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * <li>the first argument is negative zero and the second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * is a positive finite odd integer, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * <li>the first argument is negative infinity and the second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * argument is a negative finite odd integer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * then the result is negative zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * <li>If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * <li>the first argument is negative zero and the second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * is less than zero but not a finite odd integer, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * <li>the first argument is negative infinity and the second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * argument is greater than zero but not a finite odd integer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * then the result is positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * <li>If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * <li>the first argument is negative zero and the second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * is a negative finite odd integer, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * <li>the first argument is negative infinity and the second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * argument is a positive finite odd integer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * then the result is negative infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * <li>If the first argument is finite and less than zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * <li> if the second argument is a finite even integer, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * result is equal to the result of raising the absolute value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * the first argument to the power of the second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * <li>if the second argument is a finite odd integer, the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * is equal to the negative of the result of raising the absolute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * value of the first argument to the power of the second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * <li>if the second argument is finite and not an integer, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * <li>If both arguments are integers, then the result is exactly equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * to the mathematical result of raising the first argument to the power
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * of the second argument if that result can in fact be represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * exactly as a {@code double} value.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * <p>(In the foregoing descriptions, a floating-point value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * considered to be an integer if and only if it is finite and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * fixed point of the method {@link #ceil ceil} or,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * equivalently, a fixed point of the method {@link #floor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * floor}. A value is a fixed point of a one-argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * method if and only if the result of applying the method to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * value is equal to the value.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * <p>The computed result must be within 1 ulp of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * Results must be semi-monotonic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * @param   a   the base.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * @param   b   the exponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * @return  the value {@code a}<sup>{@code b}</sup>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    public static double pow(double a, double b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        return StrictMath.pow(a, b); // default impl. delegates to StrictMath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    /**
9269
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
   630
     * Returns the closest {@code int} to the argument, with ties
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
   631
     * rounding up.
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
   632
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * <ul><li>If the argument is NaN, the result is 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * <li>If the argument is negative infinity or any value less than or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * equal to the value of {@code Integer.MIN_VALUE}, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * equal to the value of {@code Integer.MIN_VALUE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * <li>If the argument is positive infinity or any value greater than or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * equal to the value of {@code Integer.MAX_VALUE}, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * equal to the value of {@code Integer.MAX_VALUE}.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * @param   a   a floating-point value to be rounded to an integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * @return  the value of the argument rounded to the nearest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     *          {@code int} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * @see     java.lang.Integer#MAX_VALUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @see     java.lang.Integer#MIN_VALUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    public static int round(float a) {
9269
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
   650
        if (a != 0x1.fffffep-2f) // greatest float value less than 0.5
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
   651
            return (int)floor(a + 0.5f);
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
   652
        else
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
   653
            return 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    /**
9269
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
   657
     * Returns the closest {@code long} to the argument, with ties
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
   658
     * rounding up.
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
   659
     *
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
   660
     * <p>Special cases:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * <ul><li>If the argument is NaN, the result is 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * <li>If the argument is negative infinity or any value less than or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * equal to the value of {@code Long.MIN_VALUE}, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * equal to the value of {@code Long.MIN_VALUE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * <li>If the argument is positive infinity or any value greater than or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * equal to the value of {@code Long.MAX_VALUE}, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * equal to the value of {@code Long.MAX_VALUE}.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * @param   a   a floating-point value to be rounded to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     *          {@code long}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * @return  the value of the argument rounded to the nearest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     *          {@code long} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * @see     java.lang.Long#MAX_VALUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * @see     java.lang.Long#MIN_VALUE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    public static long round(double a) {
9269
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
   677
        if (a != 0x1.fffffffffffffp-2) // greatest double value less than 0.5
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
   678
            return (long)floor(a + 0.5d);
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
   679
        else
f66626469aa8 6430675: Math.round has surprising behavior for 0x1.fffffffffffffp-2
darcy
parents: 7668
diff changeset
   680
            return 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    private static Random randomNumberGenerator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
5781
11a42d91eb56 6959259: Minor improvements to static Random field caching
martin
parents: 5506
diff changeset
   685
    private static synchronized Random initRNG() {
11a42d91eb56 6959259: Minor improvements to static Random field caching
martin
parents: 5506
diff changeset
   686
        Random rnd = randomNumberGenerator;
11a42d91eb56 6959259: Minor improvements to static Random field caching
martin
parents: 5506
diff changeset
   687
        return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * Returns a {@code double} value with a positive sign, greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * than or equal to {@code 0.0} and less than {@code 1.0}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * Returned values are chosen pseudorandomly with (approximately)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * uniform distribution from that range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * <p>When this method is first called, it creates a single new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * pseudorandom-number generator, exactly as if by the expression
5781
11a42d91eb56 6959259: Minor improvements to static Random field caching
martin
parents: 5506
diff changeset
   698
     *
11a42d91eb56 6959259: Minor improvements to static Random field caching
martin
parents: 5506
diff changeset
   699
     * <blockquote>{@code new java.util.Random()}</blockquote>
11a42d91eb56 6959259: Minor improvements to static Random field caching
martin
parents: 5506
diff changeset
   700
     *
11a42d91eb56 6959259: Minor improvements to static Random field caching
martin
parents: 5506
diff changeset
   701
     * This new pseudorandom-number generator is used thereafter for
11a42d91eb56 6959259: Minor improvements to static Random field caching
martin
parents: 5506
diff changeset
   702
     * all calls to this method and is used nowhere else.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * <p>This method is properly synchronized to allow correct use by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * more than one thread. However, if many threads need to generate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * pseudorandom numbers at a great rate, it may reduce contention
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * for each thread to have its own pseudorandom-number generator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * @return  a pseudorandom {@code double} greater than or equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * 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
   711
     * @see Random#nextDouble()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    public static double random() {
5781
11a42d91eb56 6959259: Minor improvements to static Random field caching
martin
parents: 5506
diff changeset
   714
        Random rnd = randomNumberGenerator;
11a42d91eb56 6959259: Minor improvements to static Random field caching
martin
parents: 5506
diff changeset
   715
        if (rnd == null) rnd = initRNG();
11a42d91eb56 6959259: Minor improvements to static Random field caching
martin
parents: 5506
diff changeset
   716
        return rnd.nextDouble();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * Returns the absolute value of an {@code int} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * If the argument is not negative, the argument is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * If the argument is negative, the negation of the argument is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * <p>Note that if the argument is equal to the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * {@link Integer#MIN_VALUE}, the most negative representable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * {@code int} value, the result is that same value, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * @param   a   the argument whose absolute value is to be determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * @return  the absolute value of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    public static int abs(int a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        return (a < 0) ? -a : a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * Returns the absolute value of a {@code long} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * If the argument is not negative, the argument is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * If the argument is negative, the negation of the argument is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * <p>Note that if the argument is equal to the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * {@link Long#MIN_VALUE}, the most negative representable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * {@code long} value, the result is that same value, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * is negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @param   a   the argument whose absolute value is to be determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * @return  the absolute value of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    public static long abs(long a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        return (a < 0) ? -a : a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * Returns the absolute value of a {@code float} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * If the argument is not negative, the argument is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * If the argument is negative, the negation of the argument is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * <ul><li>If the argument is positive zero or negative zero, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * result is positive zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * <li>If the argument is infinite, the result is positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * <li>If the argument is NaN, the result is NaN.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * In other words, the result is the same as the value of the expression:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * <p>{@code Float.intBitsToFloat(0x7fffffff & Float.floatToIntBits(a))}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * @param   a   the argument whose absolute value is to be determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * @return  the absolute value of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    public static float abs(float a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        return (a <= 0.0F) ? 0.0F - a : a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * Returns the absolute value of a {@code double} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * If the argument is not negative, the argument is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * If the argument is negative, the negation of the argument is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * <ul><li>If the argument is positive zero or negative zero, the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * is positive zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * <li>If the argument is infinite, the result is positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * <li>If the argument is NaN, the result is NaN.</ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * In other words, the result is the same as the value of the expression:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * <p>{@code Double.longBitsToDouble((Double.doubleToLongBits(a)<<1)>>>1)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * @param   a   the argument whose absolute value is to be determined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * @return  the absolute value of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    public static double abs(double a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        return (a <= 0.0D) ? 0.0D - a : a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * Returns the greater of two {@code int} values. That is, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * result is the argument closer to the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * {@link Integer#MAX_VALUE}. If the arguments have the same value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * the result is that same value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * @param   a   an argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @param   b   another argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * @return  the larger of {@code a} and {@code b}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    public static int max(int a, int b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        return (a >= b) ? a : b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * Returns the greater of two {@code long} values. That is, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * result is the argument closer to the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * {@link Long#MAX_VALUE}. If the arguments have the same value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * the result is that same value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * @param   a   an argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * @param   b   another argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * @return  the larger of {@code a} and {@code b}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    public static long max(long a, long b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        return (a >= b) ? a : b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    private static long negativeZeroFloatBits = Float.floatToIntBits(-0.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    private static long negativeZeroDoubleBits = Double.doubleToLongBits(-0.0d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * Returns the greater of two {@code float} values.  That is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * the result is the argument closer to positive infinity. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * arguments have the same value, the result is that same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * value. If either value is NaN, then the result is NaN.  Unlike
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * the numerical comparison operators, this method considers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * negative zero to be strictly smaller than positive zero. If one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * argument is positive zero and the other negative zero, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * result is positive zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * @param   a   an argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * @param   b   another argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * @return  the larger of {@code a} and {@code b}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    public static float max(float a, float b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        if (a != a) return a;   // a is NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        if ((a == 0.0f) && (b == 0.0f)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            && (Float.floatToIntBits(a) == negativeZeroFloatBits)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        return (a >= b) ? a : b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * Returns the greater of two {@code double} values.  That
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * is, the result is the argument closer to positive infinity. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * the arguments have the same value, the result is that same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * value. If either value is NaN, then the result is NaN.  Unlike
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * the numerical comparison operators, this method considers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * negative zero to be strictly smaller than positive zero. If one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * argument is positive zero and the other negative zero, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * result is positive zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * @param   a   an argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * @param   b   another argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @return  the larger of {@code a} and {@code b}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    public static double max(double a, double b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        if (a != a) return a;   // a is NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        if ((a == 0.0d) && (b == 0.0d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            && (Double.doubleToLongBits(a) == negativeZeroDoubleBits)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
        return (a >= b) ? a : b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * Returns the smaller of two {@code int} values. That is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * the result the argument closer to the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * {@link Integer#MIN_VALUE}.  If the arguments have the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * value, the result is that same value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * @param   a   an argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * @param   b   another argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * @return  the smaller of {@code a} and {@code b}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    public static int min(int a, int b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        return (a <= b) ? a : b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * Returns the smaller of two {@code long} values. That is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * the result is the argument closer to the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * {@link Long#MIN_VALUE}. If the arguments have the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * value, the result is that same value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * @param   a   an argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * @param   b   another argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * @return  the smaller of {@code a} and {@code b}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    public static long min(long a, long b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        return (a <= b) ? a : b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * Returns the smaller of two {@code float} values.  That is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * the result is the value closer to negative infinity. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * arguments have the same value, the result is that same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * value. If either value is NaN, then the result is NaN.  Unlike
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * the numerical comparison operators, this method considers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * negative zero to be strictly smaller than positive zero.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * one argument is positive zero and the other is negative zero,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * the result is negative zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * @param   a   an argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * @param   b   another argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * @return  the smaller of {@code a} and {@code b}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    public static float min(float a, float b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        if (a != a) return a;   // a is NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        if ((a == 0.0f) && (b == 0.0f)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            && (Float.floatToIntBits(b) == negativeZeroFloatBits)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        return (a <= b) ? a : b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * Returns the smaller of two {@code double} values.  That
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * is, the result is the value closer to negative infinity. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * arguments have the same value, the result is that same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * value. If either value is NaN, then the result is NaN.  Unlike
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * the numerical comparison operators, this method considers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * negative zero to be strictly smaller than positive zero. If one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * argument is positive zero and the other is negative zero, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * result is negative zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * @param   a   an argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * @param   b   another argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * @return  the smaller of {@code a} and {@code b}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    public static double min(double a, double b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        if (a != a) return a;   // a is NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        if ((a == 0.0d) && (b == 0.0d)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            && (Double.doubleToLongBits(b) == negativeZeroDoubleBits)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        return (a <= b) ? a : b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    /**
10122
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
   943
     * 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
   944
     * the last place, of a {@code double} value is the positive
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
   945
     * distance between this floating-point value and the {@code
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
   946
     * double} value next larger in magnitude.  Note that for non-NaN
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
   947
     * <i>x</i>, <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * <p>Special Cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * <li> If the argument is NaN, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * <li> If the argument is positive or negative infinity, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * result is positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * <li> If the argument is positive or negative zero, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * {@code Double.MIN_VALUE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * <li> If the argument is &plusmn;{@code Double.MAX_VALUE}, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * the result is equal to 2<sup>971</sup>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * @param d the floating-point value whose ulp is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * @return the size of an ulp of the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * @author Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    public static double ulp(double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        return sun.misc.FpUtils.ulp(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    /**
10122
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
   970
     * 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
   971
     * the last place, of a {@code float} value is the positive
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
   972
     * distance between this floating-point value and the {@code
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
   973
     * float} value next larger in magnitude.  Note that for non-NaN
bf8e763fcceb 7062430: Minor inconsistency in ulp descriptions
darcy
parents: 9269
diff changeset
   974
     * <i>x</i>, <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * <p>Special Cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * <li> If the argument is NaN, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * <li> If the argument is positive or negative infinity, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * result is positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * <li> If the argument is positive or negative zero, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * {@code Float.MIN_VALUE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * <li> If the argument is &plusmn;{@code Float.MAX_VALUE}, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * the result is equal to 2<sup>104</sup>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * @param f the floating-point value whose ulp is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * @return the size of an ulp of the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * @author Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    public static float ulp(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        return sun.misc.FpUtils.ulp(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * Returns the signum function of the argument; zero if the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * is zero, 1.0 if the argument is greater than zero, -1.0 if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * argument is less than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * <p>Special Cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * <li> If the argument is NaN, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * <li> If the argument is positive zero or negative zero, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     *      result is the same as the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * @param d the floating-point value whose signum is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * @return the signum function of the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * @author Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
    public static double signum(double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        return sun.misc.FpUtils.signum(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * Returns the signum function of the argument; zero if the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * is zero, 1.0f if the argument is greater than zero, -1.0f if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * argument is less than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * <p>Special Cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * <li> If the argument is NaN, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * <li> If the argument is positive zero or negative zero, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     *      result is the same as the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * @param f the floating-point value whose signum is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * @return the signum function of the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * @author Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    public static float signum(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        return sun.misc.FpUtils.signum(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * Returns the hyperbolic sine of a {@code double} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * The hyperbolic sine of <i>x</i> is defined to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * (<i>e<sup>x</sup>&nbsp;-&nbsp;e<sup>-x</sup></i>)/2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * where <i>e</i> is {@linkplain Math#E Euler's number}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * <p>Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * <li>If the argument is NaN, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * <li>If the argument is infinite, then the result is an infinity
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * with the same sign as the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * <li>If the argument is zero, then the result is a zero with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * same sign as the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * <p>The computed result must be within 2.5 ulps of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * @param   x The number whose hyperbolic sine is to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * @return  The hyperbolic sine of {@code x}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    public static double sinh(double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        return StrictMath.sinh(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * Returns the hyperbolic cosine of a {@code double} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * The hyperbolic cosine of <i>x</i> is defined to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * (<i>e<sup>x</sup>&nbsp;+&nbsp;e<sup>-x</sup></i>)/2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * where <i>e</i> is {@linkplain Math#E Euler's number}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * <p>Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * <li>If the argument is NaN, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * <li>If the argument is infinite, then the result is positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * <li>If the argument is zero, then the result is {@code 1.0}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     * <p>The computed result must be within 2.5 ulps of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * @param   x The number whose hyperbolic cosine is to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     * @return  The hyperbolic cosine of {@code x}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    public static double cosh(double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        return StrictMath.cosh(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     * Returns the hyperbolic tangent of a {@code double} value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     * The hyperbolic tangent of <i>x</i> is defined to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * (<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
  1099
     * in other words, {@linkplain Math#sinh
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * sinh(<i>x</i>)}/{@linkplain Math#cosh cosh(<i>x</i>)}.  Note
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * that the absolute value of the exact tanh is always less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * <p>Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * <li>If the argument is NaN, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * <li>If the argument is zero, then the result is a zero with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     * same sign as the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * <li>If the argument is positive infinity, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * {@code +1.0}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * <li>If the argument is negative infinity, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * {@code -1.0}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * <p>The computed result must be within 2.5 ulps of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     * The result of {@code tanh} for any finite input must have
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     * an absolute value less than or equal to 1.  Note that once the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     * exact result of tanh is within 1/2 of an ulp of the limit value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * of &plusmn;1, correctly signed &plusmn;{@code 1.0} should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * @param   x The number whose hyperbolic tangent is to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * @return  The hyperbolic tangent of {@code x}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    public static double tanh(double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        return StrictMath.tanh(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * Returns sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * without intermediate overflow or underflow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * <p>Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     * <li> If either argument is infinite, then the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * is positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * <li> If either argument is NaN and neither argument is infinite,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * <p>The computed result must be within 1 ulp of the exact
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * result.  If one parameter is held constant, the results must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * semi-monotonic in the other parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * @param x a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * @param y a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     * @return sqrt(<i>x</i><sup>2</sup>&nbsp;+<i>y</i><sup>2</sup>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
     * without intermediate overflow or underflow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    public static double hypot(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        return StrictMath.hypot(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * Returns <i>e</i><sup>x</sup>&nbsp;-1.  Note that for values of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * <i>x</i> near 0, the exact sum of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * {@code expm1(x)}&nbsp;+&nbsp;1 is much closer to the true
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * result of <i>e</i><sup>x</sup> than {@code exp(x)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * <p>Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * <li>If the argument is NaN, the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * <li>If the argument is positive infinity, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * <li>If the argument is negative infinity, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * -1.0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * <li>If the argument is zero, then the result is a zero with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     * same sign as the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     * <p>The computed result must be within 1 ulp of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * Results must be semi-monotonic.  The result of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * {@code expm1} for any finite input must be greater than or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * equal to {@code -1.0}.  Note that once the exact result of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     * <i>e</i><sup>{@code x}</sup>&nbsp;-&nbsp;1 is within 1/2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
     * ulp of the limit value -1, {@code -1.0} should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
     * returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * @param   x   the exponent to raise <i>e</i> to in the computation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     *              <i>e</i><sup>{@code x}</sup>&nbsp;-1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * @return  the value <i>e</i><sup>{@code x}</sup>&nbsp;-&nbsp;1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
    public static double expm1(double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        return StrictMath.expm1(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * Returns the natural logarithm of the sum of the argument and 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * Note that for small values {@code x}, the result of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     * {@code log1p(x)} is much closer to the true result of ln(1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     * + {@code x}) than the floating-point evaluation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * {@code log(1.0+x)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * <p>Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * <li>If the argument is NaN or less than -1, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
     * <li>If the argument is positive infinity, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     * positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
     * <li>If the argument is negative one, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
     * negative infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     * <li>If the argument is zero, then the result is a zero with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     * same sign as the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * <p>The computed result must be within 1 ulp of the exact result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * Results must be semi-monotonic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * @param   x   a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * @return the value ln({@code x}&nbsp;+&nbsp;1), the natural
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * log of {@code x}&nbsp;+&nbsp;1
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    public static double log1p(double x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        return StrictMath.log1p(x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * Returns the first floating-point argument with the sign of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     * second floating-point argument.  Note that unlike the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * StrictMath#copySign(double, double) StrictMath.copySign}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * method, this method does not require NaN {@code sign}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * arguments to be treated as positive values; implementations are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     * permitted to treat some NaN arguments as positive and other NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * arguments as negative to allow greater performance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     * @param magnitude  the parameter providing the magnitude of the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     * @param sign   the parameter providing the sign of the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
     * @return a value with the magnitude of {@code magnitude}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     * and the sign of {@code sign}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    public static double copySign(double magnitude, double sign) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        return sun.misc.FpUtils.rawCopySign(magnitude, sign);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * Returns the first floating-point argument with the sign of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * second floating-point argument.  Note that unlike the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * StrictMath#copySign(float, float) StrictMath.copySign}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * method, this method does not require NaN {@code sign}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * arguments to be treated as positive values; implementations are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * permitted to treat some NaN arguments as positive and other NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * arguments as negative to allow greater performance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * @param magnitude  the parameter providing the magnitude of the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     * @param sign   the parameter providing the sign of the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * @return a value with the magnitude of {@code magnitude}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * and the sign of {@code sign}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    public static float copySign(float magnitude, float sign) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        return sun.misc.FpUtils.rawCopySign(magnitude, sign);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * Returns the unbiased exponent used in the representation of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * {@code float}.  Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * <li>If the argument is NaN or infinite, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     * {@link Float#MAX_EXPONENT} + 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     * <li>If the argument is zero or subnormal, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     * {@link Float#MIN_EXPONENT} -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     * @param f a {@code float} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     * @return the unbiased exponent of the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
    public static int getExponent(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        return sun.misc.FpUtils.getExponent(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * Returns the unbiased exponent used in the representation of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * {@code double}.  Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * <li>If the argument is NaN or infinite, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     * {@link Double#MAX_EXPONENT} + 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
     * <li>If the argument is zero or subnormal, then the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
     * {@link Double#MIN_EXPONENT} -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * @param d a {@code double} value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * @return the unbiased exponent of the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    public static int getExponent(double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        return sun.misc.FpUtils.getExponent(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     * Returns the floating-point number adjacent to the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     * argument in the direction of the second argument.  If both
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * arguments compare as equal the second argument is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     * <li> If either argument is a NaN, then NaN is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * <li> If both arguments are signed zeros, {@code direction}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     * is returned unchanged (as implied by the requirement of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * returning the second argument if the arguments compare as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     * equal).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     * <li> If {@code start} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     * &plusmn;{@link Double#MIN_VALUE} and {@code direction}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     * has a value such that the result should have a smaller
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     * magnitude, then a zero with the same sign as {@code start}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
     * <li> If {@code start} is infinite and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     * {@code direction} has a value such that the result should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
     * have a smaller magnitude, {@link Double#MAX_VALUE} with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
     * same sign as {@code start} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
     * <li> If {@code start} is equal to &plusmn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
     * {@link Double#MAX_VALUE} and {@code direction} has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
     * value such that the result should have a larger magnitude, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
     * infinity with same sign as {@code start} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     * @param start  starting floating-point value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     * @param direction value indicating which of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     * {@code start}'s neighbors or {@code start} should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     * @return The floating-point number adjacent to {@code start} in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     * direction of {@code direction}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
    public static double nextAfter(double start, double direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        return sun.misc.FpUtils.nextAfter(start, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     * Returns the floating-point number adjacent to the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     * argument in the direction of the second argument.  If both
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
     * arguments compare as equal a value equivalent to the second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
     * <li> If either argument is a NaN, then NaN is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
     * <li> If both arguments are signed zeros, a value equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * to {@code direction} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * <li> If {@code start} is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     * &plusmn;{@link Float#MIN_VALUE} and {@code direction}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     * has a value such that the result should have a smaller
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
     * magnitude, then a zero with the same sign as {@code start}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
     * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
     * <li> If {@code start} is infinite and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
     * {@code direction} has a value such that the result should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
     * have a smaller magnitude, {@link Float#MAX_VALUE} with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
     * same sign as {@code start} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     * <li> If {@code start} is equal to &plusmn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     * {@link Float#MAX_VALUE} and {@code direction} has a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
     * value such that the result should have a larger magnitude, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
     * infinity with same sign as {@code start} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * @param start  starting floating-point value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     * @param direction value indicating which of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * {@code start}'s neighbors or {@code start} should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     * be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     * @return The floating-point number adjacent to {@code start} in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     * direction of {@code direction}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
    public static float nextAfter(float start, double direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        return sun.misc.FpUtils.nextAfter(start, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     * Returns the floating-point value adjacent to {@code d} in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     * the direction of positive infinity.  This method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * semantically equivalent to {@code nextAfter(d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     * implementation may run faster than its equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * {@code nextAfter} call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     * <p>Special Cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * <li> If the argument is NaN, the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * <li> If the argument is positive infinity, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * <li> If the argument is zero, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * {@link Double#MIN_VALUE}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * @param d starting floating-point value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * @return The adjacent floating-point value closer to positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
    public static double nextUp(double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        return sun.misc.FpUtils.nextUp(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * Returns the floating-point value adjacent to {@code f} in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     * the direction of positive infinity.  This method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     * semantically equivalent to {@code nextAfter(f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     * Float.POSITIVE_INFINITY)}; however, a {@code nextUp}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     * implementation may run faster than its equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     * {@code nextAfter} call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     * <p>Special Cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     * <li> If the argument is NaN, the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     * <li> If the argument is positive infinity, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     * <li> If the argument is zero, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
     * {@link Float#MIN_VALUE}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     * @param f starting floating-point value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     * @return The adjacent floating-point value closer to positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     * infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
    public static float nextUp(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
        return sun.misc.FpUtils.nextUp(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     * Return {@code d} &times;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     * by a single correctly rounded floating-point multiply to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     * member of the double value set.  See the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
     * Language Specification for a discussion of floating-point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     * value sets.  If the exponent of the result is between {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
     * Double#MIN_EXPONENT} and {@link Double#MAX_EXPONENT}, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     * answer is calculated exactly.  If the exponent of the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     * would be larger than {@code Double.MAX_EXPONENT}, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     * infinity is returned.  Note that if the result is subnormal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     * precision may be lost; that is, when {@code scalb(x, n)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     * <i>x</i>.  When the result is non-NaN, the result has the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     * sign as {@code d}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * <p>Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     * <li> If the first argument is NaN, NaN is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     * <li> If the first argument is infinite, then an infinity of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
     * same sign is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     * <li> If the first argument is zero, then a zero of the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     * sign is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     * @param d number to be scaled by a power of two.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     * @param scaleFactor power of 2 used to scale {@code d}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     * @return {@code d} &times; 2<sup>{@code scaleFactor}</sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
    public static double scalb(double d, int scaleFactor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        return sun.misc.FpUtils.scalb(d, scaleFactor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
     * Return {@code f} &times;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
     * 2<sup>{@code scaleFactor}</sup> rounded as if performed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
     * by a single correctly rounded floating-point multiply to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
     * member of the float value set.  See the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
     * Language Specification for a discussion of floating-point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
     * value sets.  If the exponent of the result is between {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
     * Float#MIN_EXPONENT} and {@link Float#MAX_EXPONENT}, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
     * answer is calculated exactly.  If the exponent of the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
     * would be larger than {@code Float.MAX_EXPONENT}, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
     * infinity is returned.  Note that if the result is subnormal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
     * precision may be lost; that is, when {@code scalb(x, n)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
     * <i>x</i>.  When the result is non-NaN, the result has the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
     * sign as {@code f}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
     * <p>Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
     * <li> If the first argument is NaN, NaN is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
     * <li> If the first argument is infinite, then an infinity of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
     * same sign is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
     * <li> If the first argument is zero, then a zero of the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
     * sign is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
     * @param f number to be scaled by a power of two.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
     * @param scaleFactor power of 2 used to scale {@code f}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
     * @return {@code f} &times; 2<sup>{@code scaleFactor}</sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
    public static float scalb(float f, int scaleFactor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        return sun.misc.FpUtils.scalb(f, scaleFactor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
}