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