jdk/src/share/classes/sun/misc/FpUtils.java
author alanb
Fri, 22 Feb 2013 14:04:06 +0000
changeset 16023 58ecc1b8327b
parent 10608 7cfca36fc79b
permissions -rw-r--r--
8008290: (profiles) Startup regression due to additional checking of JAR file manifests Reviewed-by: lancea, chegar, iris, mchung, sherman
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
     2
 * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.misc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.misc.FloatConsts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.misc.DoubleConsts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
    32
 * The class {@code FpUtils} contains static utility methods for
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
    33
 * manipulating and inspecting {@code float} and
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
    34
 * {@code double} floating-point numbers.  These methods include
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * functionality recommended or required by the IEEE 754
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * floating-point standard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class FpUtils {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * The methods in this class are reasonably implemented using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * direct or indirect bit-level manipulation of floating-point
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * values.  However, having access to the IEEE 754 recommended
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * functions would obviate the need for most programmers to engage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * in floating-point bit-twiddling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * An IEEE 754 number has three fields, from most significant bit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * to to least significant, sign, exponent, and significand.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     *  msb                                lsb
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * [sign|exponent|  fractional_significand]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Using some encoding cleverness, explained below, the high order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * bit of the logical significand does not need to be explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * stored, thus "fractional_significand" instead of simply
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * "significand" in the figure above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * For finite normal numbers, the numerical value encoded is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * (-1)^sign * 2^(exponent)*(1.fractional_significand)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * Most finite floating-point numbers are normalized; the exponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * value is reduced until the leading significand bit is 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Therefore, the leading 1 is redundant and is not explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * stored.  If a numerical value is so small it cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * normalized, it has a subnormal representation. Subnormal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * numbers don't have a leading 1 in their significand; subnormals
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * are encoding using a special exponent value.  In other words,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * the high-order bit of the logical significand can be elided in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * from the representation in either case since the bit's value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * implicit from the exponent value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * The exponent field uses a biased representation; if the bits of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * the exponent are interpreted as a unsigned integer E, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * exponent represented is E - E_bias where E_bias depends on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * floating-point format.  E can range between E_min and E_max,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * constants which depend on the floating-point format.  E_min and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * E_max are -126 and +127 for float, -1022 and +1023 for double.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * The 32-bit float format has 1 sign bit, 8 exponent bits, and 23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * bits for the significand (which is logically 24 bits wide
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * because of the implicit bit).  The 64-bit double format has 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * sign bit, 11 exponent bits, and 52 bits for the significand
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * (logically 53 bits).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * Subnormal numbers and zero have the special exponent value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * E_min -1; the numerical value represented by a subnormal is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * (-1)^sign * 2^(E_min)*(0.fractional_significand)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Zero is represented by all zero bits in the exponent and all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * zero bits in the significand; zero can have either sign.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Infinity and NaN are encoded using the exponent value E_max +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * 1.  Signed infinities have all significand bits zero; NaNs have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * at least one non-zero significand bit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * The details of IEEE 754 floating-point encoding will be used in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * the methods below without further comment.  For further
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * exposition on IEEE 754 numbers, see "IEEE Standard for Binary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Floating-Point Arithmetic" ANSI/IEEE Std 754-1985 or William
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Kahan's "Lecture Notes on the Status of IEEE Standard 754 for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Binary Floating-Point Arithmetic",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * http://www.cs.berkeley.edu/~wkahan/ieee754status/ieee754.ps.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Many of this class's methods are members of the set of IEEE 754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * recommended functions or similar functions recommended or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * required by IEEE 754R.  Discussion of various implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * techniques for these functions have occurred in:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * W.J. Cody and Jerome T. Coonen, "Algorithm 772 Functions to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Support the IEEE Standard for Binary Floating-Point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Arithmetic," ACM Transactions on Mathematical Software,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * vol. 19, no. 4, December 1993, pp. 443-451.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Joseph D. Darcy, "Writing robust IEEE recommended functions in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * ``100% Pure Java''(TM)," University of California, Berkeley
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * technical report UCB//CSD-98-1009.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Don't let anyone instantiate this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private FpUtils() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    // Helper Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    // The following helper methods are used in the implementation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    // the public recommended functions; they generally omit certain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    // tests for exception cases.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   135
     * Returns unbiased exponent of a {@code double}.
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   136
     * @deprecated Use Math.getExponent.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   138
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public static int getExponent(double d){
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   140
        return Math.getExponent(d);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   144
     * Returns unbiased exponent of a {@code float}.
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   145
     * @deprecated Use Math.getExponent.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   147
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public static int getExponent(float f){
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   149
        return Math.getExponent(f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Returns the first floating-point argument with the sign of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * second floating-point argument.  Note that unlike the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * FpUtils#copySign(double, double) copySign} method, this method
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   157
     * does not require NaN {@code sign} arguments to be treated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * as positive values; implementations are permitted to treat some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * NaN arguments as positive and other NaN arguments as negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * to allow greater performance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param magnitude  the parameter providing the magnitude of the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param sign   the parameter providing the sign of the result
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   164
     * @return a value with the magnitude of {@code magnitude}
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   165
     * and the sign of {@code sign}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @author Joseph D. Darcy
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   167
     * @deprecated Use Math.copySign.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   169
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public static double rawCopySign(double magnitude, double sign) {
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   171
        return Math.copySign(magnitude, sign);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Returns the first floating-point argument with the sign of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * second floating-point argument.  Note that unlike the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * FpUtils#copySign(float, float) copySign} method, this method
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   178
     * does not require NaN {@code sign} arguments to be treated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * as positive values; implementations are permitted to treat some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * NaN arguments as positive and other NaN arguments as negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * to allow greater performance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param magnitude  the parameter providing the magnitude of the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @param sign   the parameter providing the sign of the result
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   185
     * @return a value with the magnitude of {@code magnitude}
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   186
     * and the sign of {@code sign}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @author Joseph D. Darcy
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   188
     * @deprecated Use Math.copySign.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   190
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public static float rawCopySign(float magnitude, float sign) {
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   192
        return Math.copySign(magnitude, sign);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /* ***************************************************************** */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   198
     * Returns {@code true} if the argument is a finite
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   199
     * floating-point value; returns {@code false} otherwise (for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * NaN and infinity arguments).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   202
     * @param d the {@code double} value to be tested
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   203
     * @return {@code true} if the argument is a finite
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   204
     * floating-point value, {@code false} otherwise.
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   205
     * @deprecated Use Double.isFinite.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   207
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public static boolean isFinite(double d) {
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   209
        return Double.isFinite(d);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   213
     * Returns {@code true} if the argument is a finite
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   214
     * floating-point value; returns {@code false} otherwise (for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * NaN and infinity arguments).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   217
     * @param f the {@code float} value to be tested
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   218
     * @return {@code true} if the argument is a finite
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   219
     * floating-point value, {@code false} otherwise.
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   220
     * @deprecated Use Float.isFinite.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   222
     @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     public static boolean isFinite(float f) {
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   224
         return Float.isFinite(f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   228
     * Returns {@code true} if the specified number is infinitely
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   229
     * large in magnitude, {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * <p>Note that this method is equivalent to the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Double#isInfinite(double) Double.isInfinite} method; the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * functionality is included in this class for convenience.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param   d   the value to be tested.
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   236
     * @return  {@code true} if the value of the argument is positive
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   237
     *          infinity or negative infinity; {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public static boolean isInfinite(double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        return Double.isInfinite(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   244
     * Returns {@code true} if the specified number is infinitely
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   245
     * large in magnitude, {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * <p>Note that this method is equivalent to the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * Float#isInfinite(float) Float.isInfinite} method; the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * functionality is included in this class for convenience.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @param   f   the value to be tested.
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   252
     * @return  {@code true} if the argument is positive infinity or
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   253
     *          negative infinity; {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     public static boolean isInfinite(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
         return Float.isInfinite(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   260
     * Returns {@code true} if the specified number is a
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   261
     * Not-a-Number (NaN) value, {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * <p>Note that this method is equivalent to the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Double#isNaN(double) Double.isNaN} method; the functionality is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * included in this class for convenience.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @param   d   the value to be tested.
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   268
     * @return  {@code true} if the value of the argument is NaN;
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   269
     *          {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public static boolean isNaN(double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        return Double.isNaN(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   276
     * Returns {@code true} if the specified number is a
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   277
     * Not-a-Number (NaN) value, {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <p>Note that this method is equivalent to the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Float#isNaN(float) Float.isNaN} method; the functionality is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * included in this class for convenience.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param   f   the value to be tested.
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   284
     * @return  {@code true} if the argument is NaN;
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   285
     *          {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     public static boolean isNaN(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return Float.isNaN(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   292
     * Returns {@code true} if the unordered relation holds
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * between the two arguments.  When two floating-point values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * unordered, one value is neither less than, equal to, nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * greater than the other.  For the unordered relation to be true,
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   296
     * at least one argument must be a {@code NaN}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @param arg1      the first argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param arg2      the second argument
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   300
     * @return {@code true} if at least one argument is a NaN,
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   301
     * {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public static boolean isUnordered(double arg1, double arg2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return isNaN(arg1) || isNaN(arg2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   308
     * Returns {@code true} if the unordered relation holds
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * between the two arguments.  When two floating-point values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * unordered, one value is neither less than, equal to, nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * greater than the other.  For the unordered relation to be true,
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   312
     * at least one argument must be a {@code NaN}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @param arg1      the first argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @param arg2      the second argument
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   316
     * @return {@code true} if at least one argument is a NaN,
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   317
     * {@code false} otherwise.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     public static boolean isUnordered(float arg1, float arg2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        return isNaN(arg1) || isNaN(arg2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   324
     * Returns unbiased exponent of a {@code double}; for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * subnormal values, the number is treated as if it were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * normalized.  That is for all finite, non-zero, positive numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * <i>x</i>, <code>scalb(<i>x</i>, -ilogb(<i>x</i>))</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * always in the range [1, 2).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @param d floating-point number whose exponent is to be extracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @return unbiased exponent of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @author Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public static int ilogb(double d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        int exponent = getExponent(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        switch (exponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        case DoubleConsts.MAX_EXPONENT+1:       // NaN or infinity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            if( isNaN(d) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                return (1<<30);         // 2^30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            else // infinite value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                return (1<<28);         // 2^28
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        case DoubleConsts.MIN_EXPONENT-1:       // zero or subnormal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            if(d == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                return -(1<<28);        // -(2^28)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                long transducer = Double.doubleToRawLongBits(d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                 * To avoid causing slow arithmetic on subnormals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                 * the scaling to determine when d's significand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                 * is normalized is done in integer arithmetic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                 * (there must be at least one "1" bit in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                 * significand since zero has been screened out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                // isolate significand bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                transducer &= DoubleConsts.SIGNIF_BIT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                assert(transducer != 0L);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                // This loop is simple and functional. We might be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                // able to do something more clever that was faster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                // e.g. number of leading zero detection on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                // (transducer << (# exponent and sign bits).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                while (transducer <
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                       (1L << (DoubleConsts.SIGNIFICAND_WIDTH - 1))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                    transducer *= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                    exponent--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                exponent++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                assert( exponent >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                        DoubleConsts.MIN_EXPONENT - (DoubleConsts.SIGNIFICAND_WIDTH-1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                        exponent < DoubleConsts.MIN_EXPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                return exponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            assert( exponent >= DoubleConsts.MIN_EXPONENT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                    exponent <= DoubleConsts.MAX_EXPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            return exponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   394
     * Returns unbiased exponent of a {@code float}; for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * subnormal values, the number is treated as if it were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * normalized.  That is for all finite, non-zero, positive numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * <i>x</i>, <code>scalb(<i>x</i>, -ilogb(<i>x</i>))</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * always in the range [1, 2).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * <li> If the argument is NaN, then the result is 2<sup>30</sup>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * <li> If the argument is infinite, then the result is 2<sup>28</sup>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * <li> If the argument is zero, then the result is -(2<sup>28</sup>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @param f floating-point number whose exponent is to be extracted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @return unbiased exponent of the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @author Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     public static int ilogb(float f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        int exponent = getExponent(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        switch (exponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        case FloatConsts.MAX_EXPONENT+1:        // NaN or infinity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            if( isNaN(f) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                return (1<<30);         // 2^30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            else // infinite value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                return (1<<28);         // 2^28
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        case FloatConsts.MIN_EXPONENT-1:        // zero or subnormal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            if(f == 0.0f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                return -(1<<28);        // -(2^28)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                int transducer = Float.floatToRawIntBits(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                 * To avoid causing slow arithmetic on subnormals,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                 * the scaling to determine when f's significand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                 * is normalized is done in integer arithmetic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                 * (there must be at least one "1" bit in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                 * significand since zero has been screened out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                // isolate significand bits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                transducer &= FloatConsts.SIGNIF_BIT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                assert(transducer != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                // This loop is simple and functional. We might be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                // able to do something more clever that was faster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                // e.g. number of leading zero detection on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                // (transducer << (# exponent and sign bits).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                while (transducer <
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                       (1 << (FloatConsts.SIGNIFICAND_WIDTH - 1))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    transducer *= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    exponent--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                exponent++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                assert( exponent >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                        FloatConsts.MIN_EXPONENT - (FloatConsts.SIGNIFICAND_WIDTH-1) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                        exponent < FloatConsts.MIN_EXPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                return exponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            assert( exponent >= FloatConsts.MIN_EXPONENT &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    exponent <= FloatConsts.MAX_EXPONENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            return exponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * The scalb operation should be reasonably fast; however, there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * are tradeoffs in writing a method to minimize the worst case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * performance and writing a method to minimize the time for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * expected common inputs.  Some processors operate very slowly on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * subnormal operands, taking hundreds or thousands of cycles for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * one floating-point add or multiply as opposed to, say, four
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * cycles for normal operands.  For processors with very slow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * subnormal execution, scalb would be fastest if written entirely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * with integer operations; in other words, scalb would need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * include the logic of performing correct rounding of subnormal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * values.  This could be reasonably done in at most a few hundred
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * cycles.  However, this approach may penalize normal operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * since at least the exponent of the floating-point argument must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * be examined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * The approach taken in this implementation is a compromise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Floating-point multiplication is used to do most of the work;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * but knowingly multiplying by a subnormal scaling factor is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * avoided.  However, the floating-point argument is not examined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * to see whether or not it is subnormal since subnormal inputs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * are assumed to be rare.  At most three multiplies are needed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * scale from the largest to smallest exponent ranges (scaling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * down, at most two multiplies are needed if subnormal scaling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * factors are allowed).  However, in this implementation an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * expensive integer remainder operation is avoided at the cost of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * requiring five floating-point multiplies in the worst case,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * which should still be a performance win.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * If scaling of entire arrays is a concern, it would probably be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * more efficient to provide a double[] scalb(double[], int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * version of scalb to avoid having to recompute the needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * scaling factors for each floating-point value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   500
     * Return {@code d} &times;
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   501
     * 2<sup>{@code scale_factor}</sup> rounded as if performed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * by a single correctly rounded floating-point multiply to a
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7517
diff changeset
   503
     * member of the double value set.  See section 4.2.3 of
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7517
diff changeset
   504
     * <cite>The Java&trade; Language Specification</cite>
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7517
diff changeset
   505
     * for a discussion of floating-point
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * value sets.  If the exponent of the result is between the
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   507
     * {@code double}'s minimum exponent and maximum exponent,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * the answer is calculated exactly.  If the exponent of the
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   509
     * result would be larger than {@code doubles}'s maximum
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * exponent, an infinity is returned.  Note that if the result is
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   511
     * subnormal, precision may be lost; that is, when {@code scalb(x,
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   512
     * n)} is subnormal, {@code scalb(scalb(x, n), -n)} may
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * not equal <i>x</i>.  When the result is non-NaN, the result has
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   514
     * the same sign as {@code d}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * <li> If the first argument is NaN, NaN is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * <li> If the first argument is infinite, then an infinity of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * same sign is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * <li> If the first argument is zero, then a zero of the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * sign is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @param d number to be scaled by a power of two.
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   527
     * @param scale_factor power of 2 used to scale {@code d}
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   528
     * @return {@code d * }2<sup>{@code scale_factor}</sup>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @author Joseph D. Darcy
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   530
     * @deprecated Use Math.scalb.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   532
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    public static double scalb(double d, int scale_factor) {
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   534
        return Math.scalb(d, scale_factor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   538
     * Return {@code f} &times;
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   539
     * 2<sup>{@code scale_factor}</sup> rounded as if performed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * by a single correctly rounded floating-point multiply to a
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7517
diff changeset
   541
     * member of the float value set.  See section 4.2.3 of
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7517
diff changeset
   542
     * <cite>The Java&trade; Language Specification</cite>
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7517
diff changeset
   543
     * for a discussion of floating-point
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 7517
diff changeset
   544
     * value sets. If the exponent of the result is between the
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   545
     * {@code float}'s minimum exponent and maximum exponent, the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * answer is calculated exactly.  If the exponent of the result
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   547
     * would be larger than {@code float}'s maximum exponent, an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * infinity is returned.  Note that if the result is subnormal,
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   549
     * precision may be lost; that is, when {@code scalb(x, n)}
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   550
     * is subnormal, {@code scalb(scalb(x, n), -n)} may not equal
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * <i>x</i>.  When the result is non-NaN, the result has the same
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   552
     * sign as {@code f}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * <li> If the first argument is NaN, NaN is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * <li> If the first argument is infinite, then an infinity of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * same sign is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * <li> If the first argument is zero, then a zero of the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * sign is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * @param f number to be scaled by a power of two.
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   565
     * @param scale_factor power of 2 used to scale {@code f}
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   566
     * @return {@code f * }2<sup>{@code scale_factor}</sup>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @author Joseph D. Darcy
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   568
     * @deprecated Use Math.scalb.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   570
    @Deprecated
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   571
    public static float scalb(float f, int scale_factor) {
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   572
        return Math.scalb(f, scale_factor);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * Returns the floating-point number adjacent to the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * argument in the direction of the second argument.  If both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * arguments compare as equal the second argument is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * <li> If either argument is a NaN, then NaN is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     *
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   585
     * <li> If both arguments are signed zeros, {@code direction}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * is returned unchanged (as implied by the requirement of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * returning the second argument if the arguments compare as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * equal).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   590
     * <li> If {@code start} is
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   591
     * &plusmn;{@code Double.MIN_VALUE} and {@code direction}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * has a value such that the result should have a smaller
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   593
     * magnitude, then a zero with the same sign as {@code start}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     *
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   596
     * <li> If {@code start} is infinite and
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   597
     * {@code direction} has a value such that the result should
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   598
     * have a smaller magnitude, {@code Double.MAX_VALUE} with the
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   599
     * same sign as {@code start} is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   601
     * <li> If {@code start} is equal to &plusmn;
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   602
     * {@code Double.MAX_VALUE} and {@code direction} has a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * value such that the result should have a larger magnitude, an
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   604
     * infinity with same sign as {@code start} is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * @param start     starting floating-point value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @param direction value indicating which of
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   609
     * {@code start}'s neighbors or {@code start} should
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * be returned
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   611
     * @return The floating-point number adjacent to {@code start} in the
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   612
     * direction of {@code direction}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @author Joseph D. Darcy
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   614
     * @deprecated Use Math.nextAfter
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   616
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    public static double nextAfter(double start, double direction) {
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   618
        return Math.nextAfter(start, direction);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * Returns the floating-point number adjacent to the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * argument in the direction of the second argument.  If both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * arguments compare as equal, the second argument is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * Special cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * <li> If either argument is a NaN, then NaN is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     *
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   631
     * <li> If both arguments are signed zeros, a {@code float}
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   632
     * zero with the same sign as {@code direction} is returned
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * (as implied by the requirement of returning the second argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * if the arguments compare as equal).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   636
     * <li> If {@code start} is
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   637
     * &plusmn;{@code Float.MIN_VALUE} and {@code direction}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * has a value such that the result should have a smaller
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   639
     * magnitude, then a zero with the same sign as {@code start}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     *
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   642
     * <li> If {@code start} is infinite and
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   643
     * {@code direction} has a value such that the result should
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   644
     * have a smaller magnitude, {@code Float.MAX_VALUE} with the
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   645
     * same sign as {@code start} is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   647
     * <li> If {@code start} is equal to &plusmn;
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   648
     * {@code Float.MAX_VALUE} and {@code direction} has a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * value such that the result should have a larger magnitude, an
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   650
     * infinity with same sign as {@code start} is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * @param start     starting floating-point value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @param direction value indicating which of
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   655
     * {@code start}'s neighbors or {@code start} should
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * be returned
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   657
     * @return The floating-point number adjacent to {@code start} in the
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   658
     * direction of {@code direction}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @author Joseph D. Darcy
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   660
     * @deprecated Use Math.nextAfter.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   662
    @Deprecated
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   663
    public static float nextAfter(float start, double direction) {
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   664
        return Math.nextAfter(start, direction);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   668
     * Returns the floating-point value adjacent to {@code d} in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * the direction of positive infinity.  This method is
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   670
     * semantically equivalent to {@code nextAfter(d,
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   671
     * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * implementation may run faster than its equivalent
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   673
     * {@code nextAfter} call.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * <p>Special Cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * <li> If the argument is NaN, the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * <li> If the argument is positive infinity, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * <li> If the argument is zero, the result is
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   683
     * {@code Double.MIN_VALUE}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * @param d  starting floating-point value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * @return The adjacent floating-point value closer to positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * @author Joseph D. Darcy
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   691
     * @deprecated use Math.nextUp.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   693
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    public static double nextUp(double d) {
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   695
        return Math.nextUp(d);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   699
     * Returns the floating-point value adjacent to {@code f} in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * the direction of positive infinity.  This method is
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   701
     * semantically equivalent to {@code nextAfter(f,
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   702
     * Double.POSITIVE_INFINITY)}; however, a {@code nextUp}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * implementation may run faster than its equivalent
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   704
     * {@code nextAfter} call.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * <p>Special Cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * <li> If the argument is NaN, the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * <li> If the argument is positive infinity, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * <li> If the argument is zero, the result is
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   714
     * {@code Float.MIN_VALUE}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @param f  starting floating-point value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * @return The adjacent floating-point value closer to positive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * @author Joseph D. Darcy
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   722
     * @deprecated Use Math.nextUp.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   724
    @Deprecated
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   725
    public static float nextUp(float f) {
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   726
        return Math.nextUp(f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   730
     * Returns the floating-point value adjacent to {@code d} in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * the direction of negative infinity.  This method is
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   732
     * semantically equivalent to {@code nextAfter(d,
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   733
     * Double.NEGATIVE_INFINITY)}; however, a
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   734
     * {@code nextDown} implementation may run faster than its
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   735
     * equivalent {@code nextAfter} call.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * <p>Special Cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * <li> If the argument is NaN, the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * <li> If the argument is negative infinity, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * negative infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * <li> If the argument is zero, the result is
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   745
     * {@code -Double.MIN_VALUE}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * @param d  starting floating-point value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * @return The adjacent floating-point value closer to negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * @author Joseph D. Darcy
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   753
     * @deprecated Use Math.nextDown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     */
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   755
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    public static double nextDown(double d) {
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   757
        return Math.nextDown(d);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
    /**
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   761
     * Returns the floating-point value adjacent to {@code f} in
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * the direction of negative infinity.  This method is
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   763
     * semantically equivalent to {@code nextAfter(f,
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   764
     * Float.NEGATIVE_INFINITY)}; however, a
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   765
     * {@code nextDown} implementation may run faster than its
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   766
     * equivalent {@code nextAfter} call.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * <p>Special Cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * <li> If the argument is NaN, the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * <li> If the argument is negative infinity, the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * negative infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * <li> If the argument is zero, the result is
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   776
     * {@code -Float.MIN_VALUE}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * @param f  starting floating-point value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * @return The adjacent floating-point value closer to negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * @author Joseph D. Darcy
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   784
     * @deprecated Use Math.nextDown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     */
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   786
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    public static double nextDown(float f) {
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   788
        return Math.nextDown(f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * Returns the first floating-point argument with the sign of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * second floating-point argument.  For this method, a NaN
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   794
     * {@code sign} argument is always treated as if it were
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * positive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * @param magnitude  the parameter providing the magnitude of the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @param sign   the parameter providing the sign of the result
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   799
     * @return a value with the magnitude of {@code magnitude}
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   800
     * and the sign of {@code sign}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * @author Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @since 1.5
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   803
     * @deprecated Use StrictMath.copySign.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   805
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    public static double copySign(double magnitude, double sign) {
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   807
        return StrictMath.copySign(magnitude, sign);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * Returns the first floating-point argument with the sign of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * second floating-point argument.  For this method, a NaN
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   813
     * {@code sign} argument is always treated as if it were
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * positive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * @param magnitude  the parameter providing the magnitude of the result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * @param sign   the parameter providing the sign of the result
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   818
     * @return a value with the magnitude of {@code magnitude}
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   819
     * and the sign of {@code sign}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * @author Joseph D. Darcy
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   821
     * @deprecated Use StrictMath.copySign.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   823
    @Deprecated
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   824
    public static float copySign(float magnitude, float sign) {
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   825
        return StrictMath.copySign(magnitude, sign);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * Returns the size of an ulp of the argument.  An ulp of a
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   830
     * {@code double} value is the positive distance between this
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   831
     * floating-point value and the {@code double} value next
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * larger in magnitude.  Note that for non-NaN <i>x</i>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * <p>Special Cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * <li> If the argument is NaN, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * <li> If the argument is positive or negative infinity, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * result is positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * <li> If the argument is positive or negative zero, then the result is
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   841
     * {@code Double.MIN_VALUE}.
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   842
     * <li> If the argument is &plusmn;{@code Double.MAX_VALUE}, then
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * the result is equal to 2<sup>971</sup>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * @param d the floating-point value whose ulp is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @return the size of an ulp of the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * @author Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * @since 1.5
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   850
     * @deprecated Use Math.ulp.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   852
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    public static double ulp(double d) {
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   854
        return Math.ulp(d);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * Returns the size of an ulp of the argument.  An ulp of a
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   859
     * {@code float} value is the positive distance between this
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   860
     * floating-point value and the {@code float} value next
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * larger in magnitude.  Note that for non-NaN <i>x</i>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * <code>ulp(-<i>x</i>) == ulp(<i>x</i>)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * <p>Special Cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * <li> If the argument is NaN, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * <li> If the argument is positive or negative infinity, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * result is positive infinity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * <li> If the argument is positive or negative zero, then the result is
7517
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   870
     * {@code Float.MIN_VALUE}.
7303bc0e78d6 7002594: Math.max and Math.min should use floatToRawIntBits() to check for -0.0
darcy
parents: 5506
diff changeset
   871
     * <li> If the argument is &plusmn;{@code Float.MAX_VALUE}, then
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * the result is equal to 2<sup>104</sup>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * @param f the floating-point value whose ulp is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * @return the size of an ulp of the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * @author Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * @since 1.5
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   879
     * @deprecated Use Math.ulp.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   881
     @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     public static float ulp(float f) {
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   883
        return Math.ulp(f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * Returns the signum function of the argument; zero if the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * is zero, 1.0 if the argument is greater than zero, -1.0 if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * argument is less than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * <p>Special Cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * <li> If the argument is NaN, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * <li> If the argument is positive zero or negative zero, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     *      result is the same as the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * @param d the floating-point value whose signum is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * @return the signum function of the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * @author Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * @since 1.5
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   902
     * @deprecated Use Math.signum.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   904
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    public static double signum(double d) {
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   906
        return Math.signum(d);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * Returns the signum function of the argument; zero if the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * is zero, 1.0f if the argument is greater than zero, -1.0f if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * argument is less than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * <p>Special Cases:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * <li> If the argument is NaN, then the result is NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * <li> If the argument is positive zero or negative zero, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     *      result is the same as the argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * @param f the floating-point value whose signum is to be returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * @return the signum function of the argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * @author Joseph D. Darcy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * @since 1.5
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   925
     * @deprecated Use Math.signum.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     */
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   927
    @Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    public static float signum(float f) {
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 9734
diff changeset
   929
        return Math.signum(f);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
}