jdk/test/java/lang/Math/IeeeRecommendedTests.java
author bpb
Wed, 29 Apr 2015 16:34:49 -0700
changeset 30048 3424bede284d
parent 30046 cf2c86e1819e
child 30436 17827057ef5a
permissions -rw-r--r--
8078672: Print and allow setting by Java property seeds used to initialize Random instances in java.lang numerics tests Summary: Add ability to initial the random number generator from the system property "seed" and print to STDOUT the seed value actually used. Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     1
/*
30048
3424bede284d 8078672: Print and allow setting by Java property seeds used to initialize Random instances in java.lang numerics tests
bpb
parents: 30046
diff changeset
     2
 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     4
 *
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     7
 * published by the Free Software Foundation.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     8
 *
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    13
 * accompanied this code).
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    14
 *
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4347
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4347
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4347
diff changeset
    21
 * questions.
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    22
 */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    23
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    24
/*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    25
 * @test
30048
3424bede284d 8078672: Print and allow setting by Java property seeds used to initialize Random instances in java.lang numerics tests
bpb
parents: 30046
diff changeset
    26
 * @library /lib/testlibrary/
3424bede284d 8078672: Print and allow setting by Java property seeds used to initialize Random instances in java.lang numerics tests
bpb
parents: 30046
diff changeset
    27
 * @build jdk.testlibrary.*
3424bede284d 8078672: Print and allow setting by Java property seeds used to initialize Random instances in java.lang numerics tests
bpb
parents: 30046
diff changeset
    28
 * @run main IeeeRecommendedTests
3424bede284d 8078672: Print and allow setting by Java property seeds used to initialize Random instances in java.lang numerics tests
bpb
parents: 30046
diff changeset
    29
 * @bug 4860891 4826732 4780454 4939441 4826652 8078672
3424bede284d 8078672: Print and allow setting by Java property seeds used to initialize Random instances in java.lang numerics tests
bpb
parents: 30046
diff changeset
    30
 * @summary Tests for IEEE 754[R] recommended functions and similar methods (use -Dseed=X to set PRNG seed)
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    31
 * @author Joseph D. Darcy
30046
cf2c86e1819e 8078334: Mark regression tests using randomness
darcy
parents: 26197
diff changeset
    32
 * @key randomness
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    33
 */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    34
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    35
public class IeeeRecommendedTests {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    36
    private IeeeRecommendedTests(){}
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    37
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    38
    static final float  NaNf = Float.NaN;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    39
    static final double NaNd = Double.NaN;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    40
    static final float  infinityF = Float.POSITIVE_INFINITY;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    41
    static final double infinityD = Double.POSITIVE_INFINITY;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    42
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    43
    static final float  Float_MAX_VALUEmm       = 0x1.fffffcP+127f;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    44
    static final float  Float_MAX_SUBNORMAL     = 0x0.fffffeP-126f;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    45
    static final float  Float_MAX_SUBNORMALmm   = 0x0.fffffcP-126f;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    46
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    47
    static final double Double_MAX_VALUEmm      = 0x1.ffffffffffffeP+1023;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    48
    static final double Double_MAX_SUBNORMAL    = 0x0.fffffffffffffP-1022;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    49
    static final double Double_MAX_SUBNORMALmm  = 0x0.ffffffffffffeP-1022;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    50
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    51
    // Initialize shared random number generator
30048
3424bede284d 8078672: Print and allow setting by Java property seeds used to initialize Random instances in java.lang numerics tests
bpb
parents: 30046
diff changeset
    52
    static java.util.Random rand = RandomFactory.getRandom();
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    53
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    54
    /**
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    55
     * Returns a floating-point power of two in the normal range.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    56
     */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    57
    static double powerOfTwoD(int n) {
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
    58
        return Double.longBitsToDouble((((long)n + (long)Double.MAX_EXPONENT) <<
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    59
                                        (DoubleConsts.SIGNIFICAND_WIDTH-1))
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    60
                                       & DoubleConsts.EXP_BIT_MASK);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    61
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    62
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    63
    /**
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    64
     * Returns a floating-point power of two in the normal range.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    65
     */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    66
    static float powerOfTwoF(int n) {
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
    67
        return Float.intBitsToFloat(((n + Float.MAX_EXPONENT) <<
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    68
                                     (FloatConsts.SIGNIFICAND_WIDTH-1))
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    69
                                    & FloatConsts.EXP_BIT_MASK);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    70
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    71
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    72
    /* ******************** getExponent tests ****************************** */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    73
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    74
    /*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    75
     * The tests for getExponent should test the special values (NaN, +/-
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    76
     * infinity, etc.), test the endpoints of each binade (set of
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    77
     * floating-point values with the same exponent), and for good
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    78
     * measure, test some random values within each binade.  Testing
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    79
     * the endpoints of each binade includes testing both positive and
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    80
     * negative numbers.  Subnormal values with different normalized
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    81
     * exponents should be tested too.  Both Math and StrictMath
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    82
     * methods should return the same results.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    83
     */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    84
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    85
    /*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    86
     * Test Math.getExponent and StrictMath.getExponent with +d and -d.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    87
     */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    88
    static int testGetExponentCase(float f, int expected) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    89
        float minus_f = -f;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    90
        int failures=0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    91
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    92
        failures+=Tests.test("Math.getExponent(float)", f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    93
                             Math.getExponent(f), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    94
        failures+=Tests.test("Math.getExponent(float)", minus_f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    95
                             Math.getExponent(minus_f), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    96
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    97
        failures+=Tests.test("StrictMath.getExponent(float)", f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    98
                             StrictMath.getExponent(f), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
    99
        failures+=Tests.test("StrictMath.getExponent(float)", minus_f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   100
                             StrictMath.getExponent(minus_f), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   101
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   102
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   103
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   104
    /*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   105
     * Test Math.getExponent and StrictMath.getExponent with +d and -d.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   106
     */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   107
    static int testGetExponentCase(double d, int expected) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   108
        double minus_d = -d;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   109
        int failures=0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   110
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   111
        failures+=Tests.test("Math.getExponent(double)", d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   112
                             Math.getExponent(d), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   113
        failures+=Tests.test("Math.getExponent(double)", minus_d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   114
                             Math.getExponent(minus_d), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   115
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   116
        failures+=Tests.test("StrictMath.getExponent(double)", d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   117
                             StrictMath.getExponent(d), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   118
        failures+=Tests.test("StrictMath.getExponent(double)", minus_d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   119
                             StrictMath.getExponent(minus_d), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   120
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   121
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   122
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   123
    public static int testFloatGetExponent() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   124
        int failures = 0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   125
        float [] specialValues = {NaNf,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   126
                                   Float.POSITIVE_INFINITY,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   127
                                   +0.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   128
                                  +1.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   129
                                  +2.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   130
                                  +16.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   131
                                  +Float.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   132
                                  +Float_MAX_SUBNORMAL,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   133
                                  +Float.MIN_NORMAL,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   134
                                  +Float.MAX_VALUE
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   135
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   136
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   137
        int [] specialResults = {Float.MAX_EXPONENT + 1, // NaN results
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   138
                                 Float.MAX_EXPONENT + 1, // Infinite results
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   139
                                 Float.MIN_EXPONENT - 1, // Zero results
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   140
                                 0,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   141
                                 1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   142
                                 4,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   143
                                 Float.MIN_EXPONENT - 1,
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   144
                                 -Float.MAX_EXPONENT,
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   145
                                 Float.MIN_EXPONENT,
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   146
                                 Float.MAX_EXPONENT
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   147
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   148
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   149
        // Special value tests
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   150
        for(int i = 0; i < specialValues.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   151
            failures += testGetExponentCase(specialValues[i], specialResults[i]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   152
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   153
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   154
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   155
        // Normal exponent tests
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   156
        for(int i = Float.MIN_EXPONENT; i <= Float.MAX_EXPONENT; i++) {
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   157
            int result;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   158
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   159
            // Create power of two
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   160
            float po2 = powerOfTwoF(i);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   161
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   162
            failures += testGetExponentCase(po2, i);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   163
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   164
            // Generate some random bit patterns for the significand
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   165
            for(int j = 0; j < 10; j++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   166
                int randSignif = rand.nextInt();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   167
                float randFloat;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   168
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   169
                randFloat = Float.intBitsToFloat( // Exponent
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   170
                                                 (Float.floatToIntBits(po2)&
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   171
                                                  (~FloatConsts.SIGNIF_BIT_MASK)) |
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   172
                                                 // Significand
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   173
                                                 (randSignif &
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   174
                                                  FloatConsts.SIGNIF_BIT_MASK) );
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   175
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   176
                failures += testGetExponentCase(randFloat, i);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   177
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   178
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   179
            if (i > Float.MIN_EXPONENT) {
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 5506
diff changeset
   180
                float po2minus = Math.nextAfter(po2,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   181
                                                 Float.NEGATIVE_INFINITY);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   182
                failures += testGetExponentCase(po2minus, i-1);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   183
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   184
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   185
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   186
        // Subnormal exponent tests
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   187
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   188
        /*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   189
         * Start with MIN_VALUE, left shift, test high value, low
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   190
         * values, and random in between.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   191
         *
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   192
         * Use nextAfter to calculate, high value of previous binade,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   193
         * loop count i will indicate how many random bits, if any are
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   194
         * needed.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   195
         */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   196
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   197
        float top=Float.MIN_VALUE;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   198
        for( int i = 1;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   199
            i < FloatConsts.SIGNIFICAND_WIDTH;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   200
            i++, top *= 2.0f) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   201
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   202
            failures += testGetExponentCase(top,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   203
                                            Float.MIN_EXPONENT - 1);
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   204
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   205
            // Test largest value in next smaller binade
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   206
            if (i >= 3) {// (i == 1) would test 0.0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   207
                         // (i == 2) would just retest MIN_VALUE
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 5506
diff changeset
   208
                testGetExponentCase(Math.nextAfter(top, 0.0f),
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   209
                                    Float.MIN_EXPONENT - 1);
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   210
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   211
                if( i >= 10) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   212
                    // create a bit mask with (i-1) 1's in the low order
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   213
                    // bits
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   214
                    int mask = ~((~0)<<(i-1));
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   215
                    float randFloat = Float.intBitsToFloat( // Exponent
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   216
                                                 Float.floatToIntBits(top) |
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   217
                                                 // Significand
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   218
                                                 (rand.nextInt() & mask ) ) ;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   219
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   220
                    failures += testGetExponentCase(randFloat,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   221
                                                    Float.MIN_EXPONENT - 1);
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   222
                }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   223
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   224
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   225
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   226
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   227
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   228
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   229
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   230
    public static int testDoubleGetExponent() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   231
        int failures = 0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   232
        double [] specialValues = {NaNd,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   233
                                   infinityD,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   234
                                   +0.0,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   235
                                   +1.0,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   236
                                   +2.0,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   237
                                   +16.0,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   238
                                   +Double.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   239
                                   +Double_MAX_SUBNORMAL,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   240
                                   +Double.MIN_NORMAL,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   241
                                   +Double.MAX_VALUE
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   242
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   243
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   244
        int [] specialResults = {Double.MAX_EXPONENT + 1, // NaN results
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   245
                                 Double.MAX_EXPONENT + 1, // Infinite results
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   246
                                 Double.MIN_EXPONENT - 1, // Zero results
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   247
                                 0,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   248
                                 1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   249
                                 4,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   250
                                 Double.MIN_EXPONENT - 1,
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   251
                                 -Double.MAX_EXPONENT,
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   252
                                 Double.MIN_EXPONENT,
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   253
                                 Double.MAX_EXPONENT
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   254
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   255
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   256
        // Special value tests
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   257
        for(int i = 0; i < specialValues.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   258
            failures += testGetExponentCase(specialValues[i], specialResults[i]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   259
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   260
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   261
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   262
        // Normal exponent tests
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   263
        for(int i = Double.MIN_EXPONENT; i <= Double.MAX_EXPONENT; i++) {
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   264
            int result;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   265
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   266
            // Create power of two
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   267
            double po2 = powerOfTwoD(i);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   268
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   269
            failures += testGetExponentCase(po2, i);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   270
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   271
            // Generate some random bit patterns for the significand
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   272
            for(int j = 0; j < 10; j++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   273
                long randSignif = rand.nextLong();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   274
                double randFloat;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   275
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   276
                randFloat = Double.longBitsToDouble( // Exponent
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   277
                                                 (Double.doubleToLongBits(po2)&
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   278
                                                  (~DoubleConsts.SIGNIF_BIT_MASK)) |
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   279
                                                 // Significand
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   280
                                                 (randSignif &
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   281
                                                  DoubleConsts.SIGNIF_BIT_MASK) );
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   282
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   283
                failures += testGetExponentCase(randFloat, i);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   284
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   285
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   286
            if (i > Double.MIN_EXPONENT) {
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 5506
diff changeset
   287
                double po2minus = Math.nextAfter(po2,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   288
                                                    Double.NEGATIVE_INFINITY);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   289
                failures += testGetExponentCase(po2minus, i-1);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   290
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   291
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   292
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   293
        // Subnormal exponent tests
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   294
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   295
        /*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   296
         * Start with MIN_VALUE, left shift, test high value, low
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   297
         * values, and random in between.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   298
         *
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   299
         * Use nextAfter to calculate, high value of previous binade;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   300
         * loop count i will indicate how many random bits, if any are
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   301
         * needed.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   302
         */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   303
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   304
        double top=Double.MIN_VALUE;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   305
        for( int i = 1;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   306
            i < DoubleConsts.SIGNIFICAND_WIDTH;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   307
            i++, top *= 2.0f) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   308
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   309
            failures += testGetExponentCase(top,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   310
                                            Double.MIN_EXPONENT - 1);
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   311
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   312
            // Test largest value in next smaller binade
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   313
            if (i >= 3) {// (i == 1) would test 0.0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   314
                         // (i == 2) would just retest MIN_VALUE
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 5506
diff changeset
   315
                testGetExponentCase(Math.nextAfter(top, 0.0),
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   316
                                    Double.MIN_EXPONENT - 1);
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   317
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   318
                if( i >= 10) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   319
                    // create a bit mask with (i-1) 1's in the low order
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   320
                    // bits
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   321
                    long mask = ~((~0L)<<(i-1));
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   322
                    double randFloat = Double.longBitsToDouble( // Exponent
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   323
                                                 Double.doubleToLongBits(top) |
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   324
                                                 // Significand
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   325
                                                 (rand.nextLong() & mask ) ) ;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   326
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   327
                    failures += testGetExponentCase(randFloat,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   328
                                                    Double.MIN_EXPONENT - 1);
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   329
                }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   330
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   331
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   332
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   333
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   334
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   335
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   336
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   337
    /* ******************** nextAfter tests ****************************** */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   338
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   339
    static int testNextAfterCase(float start, double direction, float expected) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   340
        int failures=0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   341
        float minus_start = -start;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   342
        double minus_direction = -direction;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   343
        float minus_expected = -expected;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   344
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   345
        failures+=Tests.test("Math.nextAfter(float,double)", start, direction,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   346
                             Math.nextAfter(start, direction), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   347
        failures+=Tests.test("Math.nextAfter(float,double)", minus_start, minus_direction,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   348
                             Math.nextAfter(minus_start, minus_direction), minus_expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   349
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   350
        failures+=Tests.test("StrictMath.nextAfter(float,double)", start, direction,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   351
                             StrictMath.nextAfter(start, direction), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   352
        failures+=Tests.test("StrictMath.nextAfter(float,double)", minus_start, minus_direction,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   353
                             StrictMath.nextAfter(minus_start, minus_direction), minus_expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   354
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   355
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   356
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   357
    static int testNextAfterCase(double start, double direction, double expected) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   358
        int failures=0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   359
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   360
        double minus_start = -start;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   361
        double minus_direction = -direction;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   362
        double minus_expected = -expected;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   363
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   364
        failures+=Tests.test("Math.nextAfter(double,double)", start, direction,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   365
                             Math.nextAfter(start, direction), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   366
        failures+=Tests.test("Math.nextAfter(double,double)", minus_start, minus_direction,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   367
                             Math.nextAfter(minus_start, minus_direction), minus_expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   368
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   369
        failures+=Tests.test("StrictMath.nextAfter(double,double)", start, direction,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   370
                             StrictMath.nextAfter(start, direction), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   371
        failures+=Tests.test("StrictMath.nextAfter(double,double)", minus_start, minus_direction,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   372
                             StrictMath.nextAfter(minus_start, minus_direction), minus_expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   373
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   374
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   375
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   376
    public static int testFloatNextAfter() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   377
        int failures=0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   378
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   379
        /*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   380
         * Each row of the testCases matrix represents one test case
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   381
         * for nexAfter; given the input of the first two columns, the
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   382
         * result in the last column is expected.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   383
         */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   384
        float [][] testCases  = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   385
            {NaNf,              NaNf,                   NaNf},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   386
            {NaNf,              0.0f,                   NaNf},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   387
            {0.0f,              NaNf,                   NaNf},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   388
            {NaNf,              infinityF,              NaNf},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   389
            {infinityF,         NaNf,                   NaNf},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   390
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   391
            {infinityF,         infinityF,              infinityF},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   392
            {infinityF,         -infinityF,             Float.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   393
            {infinityF,         0.0f,                   Float.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   394
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   395
            {Float.MAX_VALUE,   infinityF,              infinityF},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   396
            {Float.MAX_VALUE,   -infinityF,             Float_MAX_VALUEmm},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   397
            {Float.MAX_VALUE,   Float.MAX_VALUE,        Float.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   398
            {Float.MAX_VALUE,   0.0f,                   Float_MAX_VALUEmm},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   399
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   400
            {Float_MAX_VALUEmm, Float.MAX_VALUE,        Float.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   401
            {Float_MAX_VALUEmm, infinityF,              Float.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   402
            {Float_MAX_VALUEmm, Float_MAX_VALUEmm,      Float_MAX_VALUEmm},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   403
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   404
            {Float.MIN_NORMAL,          infinityF,              Float.MIN_NORMAL+
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   405
                                                                Float.MIN_VALUE},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   406
            {Float.MIN_NORMAL,          -infinityF,             Float_MAX_SUBNORMAL},
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   407
            {Float.MIN_NORMAL,          1.0f,                   Float.MIN_NORMAL+
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   408
                                                                Float.MIN_VALUE},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   409
            {Float.MIN_NORMAL,          -1.0f,                  Float_MAX_SUBNORMAL},
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   410
            {Float.MIN_NORMAL,          Float.MIN_NORMAL,       Float.MIN_NORMAL},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   411
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   412
            {Float_MAX_SUBNORMAL,       Float.MIN_NORMAL,       Float.MIN_NORMAL},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   413
            {Float_MAX_SUBNORMAL,       Float_MAX_SUBNORMAL,    Float_MAX_SUBNORMAL},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   414
            {Float_MAX_SUBNORMAL,       0.0f,                   Float_MAX_SUBNORMALmm},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   415
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   416
            {Float_MAX_SUBNORMALmm,     Float_MAX_SUBNORMAL,    Float_MAX_SUBNORMAL},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   417
            {Float_MAX_SUBNORMALmm,     0.0f,                   Float_MAX_SUBNORMALmm-Float.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   418
            {Float_MAX_SUBNORMALmm,     Float_MAX_SUBNORMALmm,  Float_MAX_SUBNORMALmm},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   419
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   420
            {Float.MIN_VALUE,   0.0f,                   0.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   421
            {-Float.MIN_VALUE,  0.0f,                   -0.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   422
            {Float.MIN_VALUE,   Float.MIN_VALUE,        Float.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   423
            {Float.MIN_VALUE,   1.0f,                   2*Float.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   424
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   425
            // Make sure zero behavior is tested
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   426
            {0.0f,              0.0f,                   0.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   427
            {0.0f,              -0.0f,                  -0.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   428
            {-0.0f,             0.0f,                   0.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   429
            {-0.0f,             -0.0f,                  -0.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   430
            {0.0f,              infinityF,              Float.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   431
            {0.0f,              -infinityF,             -Float.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   432
            {-0.0f,             infinityF,              Float.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   433
            {-0.0f,             -infinityF,             -Float.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   434
            {0.0f,              Float.MIN_VALUE,        Float.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   435
            {0.0f,              -Float.MIN_VALUE,       -Float.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   436
            {-0.0f,             Float.MIN_VALUE,        Float.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   437
            {-0.0f,             -Float.MIN_VALUE,       -Float.MIN_VALUE}
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   438
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   439
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   440
        for(int i = 0; i < testCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   441
            failures += testNextAfterCase(testCases[i][0], testCases[i][1],
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   442
                                          testCases[i][2]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   443
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   444
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   445
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   446
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   447
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   448
    public static int testDoubleNextAfter() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   449
        int failures =0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   450
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   451
        /*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   452
         * Each row of the testCases matrix represents one test case
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   453
         * for nexAfter; given the input of the first two columns, the
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   454
         * result in the last column is expected.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   455
         */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   456
        double [][] testCases  = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   457
            {NaNd,              NaNd,                   NaNd},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   458
            {NaNd,              0.0d,                   NaNd},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   459
            {0.0d,              NaNd,                   NaNd},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   460
            {NaNd,              infinityD,              NaNd},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   461
            {infinityD,         NaNd,                   NaNd},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   462
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   463
            {infinityD,         infinityD,              infinityD},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   464
            {infinityD,         -infinityD,             Double.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   465
            {infinityD,         0.0d,                   Double.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   466
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   467
            {Double.MAX_VALUE,  infinityD,              infinityD},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   468
            {Double.MAX_VALUE,  -infinityD,             Double_MAX_VALUEmm},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   469
            {Double.MAX_VALUE,  Double.MAX_VALUE,       Double.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   470
            {Double.MAX_VALUE,  0.0d,                   Double_MAX_VALUEmm},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   471
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   472
            {Double_MAX_VALUEmm,        Double.MAX_VALUE,       Double.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   473
            {Double_MAX_VALUEmm,        infinityD,              Double.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   474
            {Double_MAX_VALUEmm,        Double_MAX_VALUEmm,     Double_MAX_VALUEmm},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   475
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   476
            {Double.MIN_NORMAL,         infinityD,              Double.MIN_NORMAL+
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   477
                                                                Double.MIN_VALUE},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   478
            {Double.MIN_NORMAL,         -infinityD,             Double_MAX_SUBNORMAL},
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   479
            {Double.MIN_NORMAL,         1.0f,                   Double.MIN_NORMAL+
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   480
                                                                Double.MIN_VALUE},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   481
            {Double.MIN_NORMAL,         -1.0f,                  Double_MAX_SUBNORMAL},
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   482
            {Double.MIN_NORMAL,         Double.MIN_NORMAL,      Double.MIN_NORMAL},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   483
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   484
            {Double_MAX_SUBNORMAL,      Double.MIN_NORMAL,      Double.MIN_NORMAL},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   485
            {Double_MAX_SUBNORMAL,      Double_MAX_SUBNORMAL,   Double_MAX_SUBNORMAL},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   486
            {Double_MAX_SUBNORMAL,      0.0d,                   Double_MAX_SUBNORMALmm},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   487
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   488
            {Double_MAX_SUBNORMALmm,    Double_MAX_SUBNORMAL,   Double_MAX_SUBNORMAL},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   489
            {Double_MAX_SUBNORMALmm,    0.0d,                   Double_MAX_SUBNORMALmm-Double.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   490
            {Double_MAX_SUBNORMALmm,    Double_MAX_SUBNORMALmm, Double_MAX_SUBNORMALmm},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   491
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   492
            {Double.MIN_VALUE,  0.0d,                   0.0d},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   493
            {-Double.MIN_VALUE, 0.0d,                   -0.0d},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   494
            {Double.MIN_VALUE,  Double.MIN_VALUE,       Double.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   495
            {Double.MIN_VALUE,  1.0f,                   2*Double.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   496
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   497
            // Make sure zero behavior is tested
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   498
            {0.0d,              0.0d,                   0.0d},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   499
            {0.0d,              -0.0d,                  -0.0d},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   500
            {-0.0d,             0.0d,                   0.0d},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   501
            {-0.0d,             -0.0d,                  -0.0d},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   502
            {0.0d,              infinityD,              Double.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   503
            {0.0d,              -infinityD,             -Double.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   504
            {-0.0d,             infinityD,              Double.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   505
            {-0.0d,             -infinityD,             -Double.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   506
            {0.0d,              Double.MIN_VALUE,       Double.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   507
            {0.0d,              -Double.MIN_VALUE,      -Double.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   508
            {-0.0d,             Double.MIN_VALUE,       Double.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   509
            {-0.0d,             -Double.MIN_VALUE,      -Double.MIN_VALUE}
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   510
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   511
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   512
        for(int i = 0; i < testCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   513
            failures += testNextAfterCase(testCases[i][0], testCases[i][1],
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   514
                                          testCases[i][2]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   515
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   516
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   517
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   518
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   519
    /* ******************** nextUp tests ********************************* */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   520
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   521
    public static int testFloatNextUp() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   522
        int failures=0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   523
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   524
        /*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   525
         * Each row of testCases represents one test case for nextUp;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   526
         * the first column is the input and the second column is the
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   527
         * expected result.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   528
         */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   529
        float testCases [][] = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   530
            {NaNf,                      NaNf},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   531
            {-infinityF,                -Float.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   532
            {-Float.MAX_VALUE,          -Float_MAX_VALUEmm},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   533
            {-Float.MIN_NORMAL,         -Float_MAX_SUBNORMAL},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   534
            {-Float_MAX_SUBNORMAL,      -Float_MAX_SUBNORMALmm},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   535
            {-Float.MIN_VALUE,          -0.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   536
            {-0.0f,                     Float.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   537
            {+0.0f,                     Float.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   538
            {Float.MIN_VALUE,           Float.MIN_VALUE*2},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   539
            {Float_MAX_SUBNORMALmm,     Float_MAX_SUBNORMAL},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   540
            {Float_MAX_SUBNORMAL,       Float.MIN_NORMAL},
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   541
            {Float.MIN_NORMAL,          Float.MIN_NORMAL+Float.MIN_VALUE},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   542
            {Float_MAX_VALUEmm,         Float.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   543
            {Float.MAX_VALUE,           infinityF},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   544
            {infinityF,                 infinityF}
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   545
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   546
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   547
        for(int i = 0; i < testCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   548
            failures+=Tests.test("Math.nextUp(float)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   549
                                 testCases[i][0], Math.nextUp(testCases[i][0]), testCases[i][1]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   550
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   551
            failures+=Tests.test("StrictMath.nextUp(float)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   552
                                 testCases[i][0], StrictMath.nextUp(testCases[i][0]), testCases[i][1]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   553
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   554
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   555
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   556
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   557
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   558
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   559
    public static int testDoubleNextUp() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   560
        int failures=0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   561
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   562
        /*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   563
         * Each row of testCases represents one test case for nextUp;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   564
         * the first column is the input and the second column is the
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   565
         * expected result.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   566
         */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   567
        double testCases [][] = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   568
            {NaNd,                      NaNd},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   569
            {-infinityD,                -Double.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   570
            {-Double.MAX_VALUE,         -Double_MAX_VALUEmm},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   571
            {-Double.MIN_NORMAL,        -Double_MAX_SUBNORMAL},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   572
            {-Double_MAX_SUBNORMAL,     -Double_MAX_SUBNORMALmm},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   573
            {-Double.MIN_VALUE,         -0.0d},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   574
            {-0.0d,                     Double.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   575
            {+0.0d,                     Double.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   576
            {Double.MIN_VALUE,          Double.MIN_VALUE*2},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   577
            {Double_MAX_SUBNORMALmm,    Double_MAX_SUBNORMAL},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   578
            {Double_MAX_SUBNORMAL,      Double.MIN_NORMAL},
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   579
            {Double.MIN_NORMAL,         Double.MIN_NORMAL+Double.MIN_VALUE},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   580
            {Double_MAX_VALUEmm,        Double.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   581
            {Double.MAX_VALUE,          infinityD},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   582
            {infinityD,                 infinityD}
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   583
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   584
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   585
        for(int i = 0; i < testCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   586
            failures+=Tests.test("Math.nextUp(double)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   587
                                 testCases[i][0], Math.nextUp(testCases[i][0]), testCases[i][1]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   588
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   589
            failures+=Tests.test("StrictMath.nextUp(double)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   590
                                 testCases[i][0], StrictMath.nextUp(testCases[i][0]), testCases[i][1]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   591
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   592
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   593
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   594
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   595
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   596
    /* ******************** nextDown tests ********************************* */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   597
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   598
    public static int testFloatNextDown() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   599
        int failures=0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   600
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   601
        /*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   602
         * Each row of testCases represents one test case for nextDown;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   603
         * the first column is the input and the second column is the
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   604
         * expected result.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   605
         */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   606
        float testCases [][] = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   607
            {NaNf,                      NaNf},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   608
            {-infinityF,                -infinityF},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   609
            {-Float.MAX_VALUE,          -infinityF},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   610
            {-Float_MAX_VALUEmm,        -Float.MAX_VALUE},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   611
            {-Float_MAX_SUBNORMAL,      -Float.MIN_NORMAL},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   612
            {-Float_MAX_SUBNORMALmm,    -Float_MAX_SUBNORMAL},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   613
            {-0.0f,                     -Float.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   614
            {+0.0f,                     -Float.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   615
            {Float.MIN_VALUE,           0.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   616
            {Float.MIN_VALUE*2,         Float.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   617
            {Float_MAX_SUBNORMAL,       Float_MAX_SUBNORMALmm},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   618
            {Float.MIN_NORMAL,          Float_MAX_SUBNORMAL},
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   619
            {Float.MIN_NORMAL+
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   620
             Float.MIN_VALUE,           Float.MIN_NORMAL},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   621
            {Float.MAX_VALUE,           Float_MAX_VALUEmm},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   622
            {infinityF,                 Float.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   623
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   624
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   625
        for(int i = 0; i < testCases.length; i++) {
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   626
            failures+=Tests.test("Math.nextDown(float)",
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   627
                                 testCases[i][0], Math.nextDown(testCases[i][0]), testCases[i][1]);
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   628
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   629
            failures+=Tests.test("StrictMath.nextDown(float)",
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   630
                                 testCases[i][0], StrictMath.nextDown(testCases[i][0]), testCases[i][1]);
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   631
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   632
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   633
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   634
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   635
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   636
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   637
    public static int testDoubleNextDown() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   638
        int failures=0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   639
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   640
        /*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   641
         * Each row of testCases represents one test case for nextDown;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   642
         * the first column is the input and the second column is the
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   643
         * expected result.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   644
         */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   645
        double testCases [][] = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   646
            {NaNd,                      NaNd},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   647
            {-infinityD,                -infinityD},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   648
            {-Double.MAX_VALUE,         -infinityD},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   649
            {-Double_MAX_VALUEmm,       -Double.MAX_VALUE},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   650
            {-Double_MAX_SUBNORMAL,     -Double.MIN_NORMAL},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   651
            {-Double_MAX_SUBNORMALmm,   -Double_MAX_SUBNORMAL},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   652
            {-0.0d,                     -Double.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   653
            {+0.0d,                     -Double.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   654
            {Double.MIN_VALUE,          0.0d},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   655
            {Double.MIN_VALUE*2,        Double.MIN_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   656
            {Double_MAX_SUBNORMAL,      Double_MAX_SUBNORMALmm},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   657
            {Double.MIN_NORMAL,         Double_MAX_SUBNORMAL},
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   658
            {Double.MIN_NORMAL+
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   659
             Double.MIN_VALUE,          Double.MIN_NORMAL},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   660
            {Double.MAX_VALUE,          Double_MAX_VALUEmm},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   661
            {infinityD,                 Double.MAX_VALUE},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   662
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   663
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   664
        for(int i = 0; i < testCases.length; i++) {
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   665
            failures+=Tests.test("Math.nextDown(double)",
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   666
                                 testCases[i][0], Math.nextDown(testCases[i][0]), testCases[i][1]);
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   667
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   668
            failures+=Tests.test("StrictMath.nextDown(double)",
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   669
                                 testCases[i][0], StrictMath.nextDown(testCases[i][0]), testCases[i][1]);
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   670
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   671
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   672
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   673
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   674
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   675
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   676
    /* ********************** boolean tests ****************************** */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   677
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   678
    /*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   679
     * Combined tests for boolean functions, isFinite, isInfinite,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   680
     * isNaN, isUnordered.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   681
     */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   682
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   683
    public static int testFloatBooleanMethods() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   684
        int failures = 0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   685
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   686
        float testCases [] = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   687
            NaNf,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   688
            -infinityF,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   689
            infinityF,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   690
            -Float.MAX_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   691
            -3.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   692
            -1.0f,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   693
            -Float.MIN_NORMAL,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   694
            -Float_MAX_SUBNORMALmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   695
            -Float_MAX_SUBNORMAL,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   696
            -Float.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   697
            -0.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   698
            +0.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   699
            Float.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   700
            Float_MAX_SUBNORMALmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   701
            Float_MAX_SUBNORMAL,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   702
            Float.MIN_NORMAL,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   703
            1.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   704
            3.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   705
            Float_MAX_VALUEmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   706
            Float.MAX_VALUE
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   707
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   708
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   709
        for(int i = 0; i < testCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   710
            // isNaN
22634
9c18aebe9229 8033416: Remove sun.misc.FpUtils
darcy
parents: 10608
diff changeset
   711
            failures+=Tests.test("Float.isNaN(float)", testCases[i],
9c18aebe9229 8033416: Remove sun.misc.FpUtils
darcy
parents: 10608
diff changeset
   712
                                 Float.isNaN(testCases[i]), (i ==0));
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   713
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   714
            // isFinite
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   715
            failures+=Tests.test("Float.isFinite(float)", testCases[i],
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   716
                                 Float.isFinite(testCases[i]), (i >= 3));
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   717
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   718
            // isInfinite
22634
9c18aebe9229 8033416: Remove sun.misc.FpUtils
darcy
parents: 10608
diff changeset
   719
            failures+=Tests.test("Float.isInfinite(float)", testCases[i],
9c18aebe9229 8033416: Remove sun.misc.FpUtils
darcy
parents: 10608
diff changeset
   720
                                 Float.isInfinite(testCases[i]), (i==1 || i==2));
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   721
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   722
            // isUnorderd
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   723
            for(int j = 0; j < testCases.length; j++) {
22634
9c18aebe9229 8033416: Remove sun.misc.FpUtils
darcy
parents: 10608
diff changeset
   724
                failures+=Tests.test("Tests.isUnordered(float, float)", testCases[i],testCases[j],
9c18aebe9229 8033416: Remove sun.misc.FpUtils
darcy
parents: 10608
diff changeset
   725
                                     Tests.isUnordered(testCases[i],testCases[j]), (i==0 || j==0));
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   726
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   727
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   728
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   729
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   730
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   731
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   732
    public static int testDoubleBooleanMethods() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   733
        int failures = 0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   734
        boolean result = false;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   735
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   736
        double testCases [] = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   737
            NaNd,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   738
            -infinityD,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   739
            infinityD,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   740
            -Double.MAX_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   741
            -3.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   742
            -1.0d,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   743
            -Double.MIN_NORMAL,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   744
            -Double_MAX_SUBNORMALmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   745
            -Double_MAX_SUBNORMAL,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   746
            -Double.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   747
            -0.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   748
            +0.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   749
            Double.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   750
            Double_MAX_SUBNORMALmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   751
            Double_MAX_SUBNORMAL,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   752
            Double.MIN_NORMAL,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   753
            1.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   754
            3.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   755
            Double_MAX_VALUEmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   756
            Double.MAX_VALUE
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   757
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   758
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   759
        for(int i = 0; i < testCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   760
            // isNaN
22634
9c18aebe9229 8033416: Remove sun.misc.FpUtils
darcy
parents: 10608
diff changeset
   761
            failures+=Tests.test("Double.isNaN(double)", testCases[i],
9c18aebe9229 8033416: Remove sun.misc.FpUtils
darcy
parents: 10608
diff changeset
   762
                                 Double.isNaN(testCases[i]), (i ==0));
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   763
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   764
            // isFinite
10608
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   765
            failures+=Tests.test("Double.isFinite(double)", testCases[i],
7cfca36fc79b 7092404: Add Math.nextDown and Double.isFinite
darcy
parents: 10598
diff changeset
   766
                                 Double.isFinite(testCases[i]), (i >= 3));
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   767
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   768
            // isInfinite
22634
9c18aebe9229 8033416: Remove sun.misc.FpUtils
darcy
parents: 10608
diff changeset
   769
            failures+=Tests.test("Double.isInfinite(double)", testCases[i],
9c18aebe9229 8033416: Remove sun.misc.FpUtils
darcy
parents: 10608
diff changeset
   770
                                 Double.isInfinite(testCases[i]), (i==1 || i==2));
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   771
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   772
            // isUnorderd
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   773
            for(int j = 0; j < testCases.length; j++) {
22634
9c18aebe9229 8033416: Remove sun.misc.FpUtils
darcy
parents: 10608
diff changeset
   774
                failures+=Tests.test("Tests.isUnordered(double, double)", testCases[i],testCases[j],
9c18aebe9229 8033416: Remove sun.misc.FpUtils
darcy
parents: 10608
diff changeset
   775
                                     Tests.isUnordered(testCases[i],testCases[j]), (i==0 || j==0));
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   776
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   777
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   778
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   779
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   780
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   781
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   782
    /* ******************** copySign tests******************************** */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   783
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   784
   public static int testFloatCopySign() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   785
        int failures = 0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   786
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   787
        // testCases[0] are logically positive numbers;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   788
        // testCases[1] are negative numbers.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   789
        float testCases [][] = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   790
            {+0.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   791
             Float.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   792
             Float_MAX_SUBNORMALmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   793
             Float_MAX_SUBNORMAL,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   794
             Float.MIN_NORMAL,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   795
             1.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   796
             3.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   797
             Float_MAX_VALUEmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   798
             Float.MAX_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   799
             infinityF,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   800
            },
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   801
            {-infinityF,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   802
             -Float.MAX_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   803
             -3.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   804
             -1.0f,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   805
             -Float.MIN_NORMAL,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   806
             -Float_MAX_SUBNORMALmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   807
             -Float_MAX_SUBNORMAL,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   808
             -Float.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   809
             -0.0f}
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   810
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   811
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   812
        float NaNs[] = {Float.intBitsToFloat(0x7fc00000),       // "positive" NaN
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   813
                        Float.intBitsToFloat(0xFfc00000)};      // "negative" NaN
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   814
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   815
        // Tests shared between raw and non-raw versions
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   816
        for(int i = 0; i < 2; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   817
            for(int j = 0; j < 2; j++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   818
                for(int m = 0; m < testCases[i].length; m++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   819
                    for(int n = 0; n < testCases[j].length; n++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   820
                        // copySign(magnitude, sign)
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   821
                        failures+=Tests.test("Math.copySign(float,float)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   822
                                             testCases[i][m],testCases[j][n],
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   823
                                             Math.copySign(testCases[i][m], testCases[j][n]),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   824
                                             (j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   825
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   826
                        failures+=Tests.test("StrictMath.copySign(float,float)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   827
                                             testCases[i][m],testCases[j][n],
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   828
                                             StrictMath.copySign(testCases[i][m], testCases[j][n]),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   829
                                             (j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   830
                    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   831
                }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   832
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   833
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   834
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   835
        // For rawCopySign, NaN may effectively have either sign bit
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   836
        // while for copySign NaNs are treated as if they always have
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   837
        // a zero sign bit (i.e. as positive numbers)
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   838
        for(int i = 0; i < 2; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   839
            for(int j = 0; j < NaNs.length; j++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   840
                for(int m = 0; m < testCases[i].length; m++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   841
                    // copySign(magnitude, sign)
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   842
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   843
                    failures += (Math.abs(Math.copySign(testCases[i][m], NaNs[j])) ==
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   844
                                 Math.abs(testCases[i][m])) ? 0:1;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   845
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   846
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   847
                    failures+=Tests.test("StrictMath.copySign(float,float)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   848
                                         testCases[i][m], NaNs[j],
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   849
                                         StrictMath.copySign(testCases[i][m], NaNs[j]),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   850
                                         Math.abs(testCases[i][m]) );
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   851
                }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   852
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   853
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   854
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   855
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   856
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   857
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   858
    public static int testDoubleCopySign() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   859
        int failures = 0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   860
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   861
        // testCases[0] are logically positive numbers;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   862
        // testCases[1] are negative numbers.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   863
        double testCases [][] = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   864
            {+0.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   865
             Double.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   866
             Double_MAX_SUBNORMALmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   867
             Double_MAX_SUBNORMAL,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   868
             Double.MIN_NORMAL,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   869
             1.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   870
             3.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   871
             Double_MAX_VALUEmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   872
             Double.MAX_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   873
             infinityD,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   874
            },
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   875
            {-infinityD,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   876
             -Double.MAX_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   877
             -3.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   878
             -1.0d,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   879
             -Double.MIN_NORMAL,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   880
             -Double_MAX_SUBNORMALmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   881
             -Double_MAX_SUBNORMAL,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   882
             -Double.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   883
             -0.0d}
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   884
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   885
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   886
        double NaNs[] = {Double.longBitsToDouble(0x7ff8000000000000L),  // "positive" NaN
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   887
                         Double.longBitsToDouble(0xfff8000000000000L),  // "negative" NaN
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   888
                         Double.longBitsToDouble(0x7FF0000000000001L),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   889
                         Double.longBitsToDouble(0xFFF0000000000001L),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   890
                         Double.longBitsToDouble(0x7FF8555555555555L),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   891
                         Double.longBitsToDouble(0xFFF8555555555555L),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   892
                         Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   893
                         Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   894
                         Double.longBitsToDouble(0x7FFDeadBeef00000L),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   895
                         Double.longBitsToDouble(0xFFFDeadBeef00000L),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   896
                         Double.longBitsToDouble(0x7FFCafeBabe00000L),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   897
                         Double.longBitsToDouble(0xFFFCafeBabe00000L)};
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   898
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   899
        // Tests shared between Math and StrictMath versions
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   900
        for(int i = 0; i < 2; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   901
            for(int j = 0; j < 2; j++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   902
                for(int m = 0; m < testCases[i].length; m++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   903
                    for(int n = 0; n < testCases[j].length; n++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   904
                        // copySign(magnitude, sign)
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   905
                        failures+=Tests.test("MathcopySign(double,double)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   906
                                             testCases[i][m],testCases[j][n],
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   907
                                             Math.copySign(testCases[i][m], testCases[j][n]),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   908
                                             (j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   909
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   910
                        failures+=Tests.test("StrictMath.copySign(double,double)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   911
                                             testCases[i][m],testCases[j][n],
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   912
                                             StrictMath.copySign(testCases[i][m], testCases[j][n]),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   913
                                             (j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   914
                    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   915
                }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   916
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   917
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   918
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   919
        // For Math.copySign, NaN may effectively have either sign bit
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   920
        // while for StrictMath.copySign NaNs are treated as if they
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   921
        // always have a zero sign bit (i.e. as positive numbers)
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   922
        for(int i = 0; i < 2; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   923
            for(int j = 0; j < NaNs.length; j++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   924
                for(int m = 0; m < testCases[i].length; m++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   925
                    // copySign(magnitude, sign)
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   926
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   927
                    failures += (Math.abs(Math.copySign(testCases[i][m], NaNs[j])) ==
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   928
                                 Math.abs(testCases[i][m])) ? 0:1;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   929
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   930
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   931
                    failures+=Tests.test("StrictMath.copySign(double,double)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   932
                                         testCases[i][m], NaNs[j],
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   933
                                         StrictMath.copySign(testCases[i][m], NaNs[j]),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   934
                                         Math.abs(testCases[i][m]) );
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   935
                }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   936
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   937
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   938
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   939
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   940
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   941
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   942
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   943
    /* ************************ scalb tests ******************************* */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   944
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   945
    static int testScalbCase(float value, int scale_factor, float expected) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   946
        int failures=0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   947
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   948
        failures+=Tests.test("Math.scalb(float,int)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   949
                             value, scale_factor,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   950
                             Math.scalb(value, scale_factor), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   951
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   952
        failures+=Tests.test("Math.scalb(float,int)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   953
                             -value, scale_factor,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   954
                             Math.scalb(-value, scale_factor), -expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   955
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   956
        failures+=Tests.test("StrictMath.scalb(float,int)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   957
                             value, scale_factor,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   958
                             StrictMath.scalb(value, scale_factor), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   959
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   960
        failures+=Tests.test("StrictMath.scalb(float,int)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   961
                             -value, scale_factor,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   962
                             StrictMath.scalb(-value, scale_factor), -expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   963
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   964
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   965
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   966
    public static int testFloatScalb() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   967
        int failures=0;
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   968
        int MAX_SCALE = Float.MAX_EXPONENT + -Float.MIN_EXPONENT +
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   969
                        FloatConsts.SIGNIFICAND_WIDTH + 1;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   970
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   971
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   972
        // Arguments x, where scalb(x,n) is x for any n.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   973
        float [] identityTestCases = {NaNf,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   974
                                      -0.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   975
                                      +0.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   976
                                      infinityF,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   977
                                      -infinityF
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   978
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   979
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   980
        float [] subnormalTestCases = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   981
            Float.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   982
            3.0f*Float.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   983
            Float_MAX_SUBNORMALmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   984
            Float_MAX_SUBNORMAL
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   985
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   986
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   987
        float [] someTestCases = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   988
            Float.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   989
            3.0f*Float.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   990
            Float_MAX_SUBNORMALmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   991
            Float_MAX_SUBNORMAL,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
   992
            Float.MIN_NORMAL,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   993
            1.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   994
            2.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   995
            3.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   996
            (float)Math.PI,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   997
            Float_MAX_VALUEmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   998
            Float.MAX_VALUE
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
   999
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1000
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1001
        int [] oneMultiplyScalingFactors = {
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1002
            Float.MIN_EXPONENT,
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1003
            Float.MIN_EXPONENT+1,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1004
            -3,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1005
            -2,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1006
            -1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1007
            0,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1008
            1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1009
            2,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1010
            3,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1011
            Float.MAX_EXPONENT-1,
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1012
            Float.MAX_EXPONENT
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1013
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1014
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1015
        int [] manyScalingFactors = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1016
            Integer.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1017
            Integer.MIN_VALUE+1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1018
            -MAX_SCALE -1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1019
            -MAX_SCALE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1020
            -MAX_SCALE+1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1021
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1022
            2*Float.MIN_EXPONENT-1,       // -253
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1023
            2*Float.MIN_EXPONENT,         // -252
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1024
            2*Float.MIN_EXPONENT+1,       // -251
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1025
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1026
            Float.MIN_EXPONENT - FloatConsts.SIGNIFICAND_WIDTH,
22634
9c18aebe9229 8033416: Remove sun.misc.FpUtils
darcy
parents: 10608
diff changeset
  1027
            FloatConsts.MIN_SUB_EXPONENT,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1028
            -Float.MAX_EXPONENT,          // -127
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1029
            Float.MIN_EXPONENT,           // -126
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1030
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1031
            -2,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1032
            -1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1033
            0,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1034
            1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1035
            2,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1036
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1037
            Float.MAX_EXPONENT-1,         // 126
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1038
            Float.MAX_EXPONENT,           // 127
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1039
            Float.MAX_EXPONENT+1,         // 128
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1040
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1041
            2*Float.MAX_EXPONENT-1,       // 253
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1042
            2*Float.MAX_EXPONENT,         // 254
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1043
            2*Float.MAX_EXPONENT+1,       // 255
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1044
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1045
            MAX_SCALE-1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1046
            MAX_SCALE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1047
            MAX_SCALE+1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1048
            Integer.MAX_VALUE-1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1049
            Integer.MAX_VALUE
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1050
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1051
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1052
        // Test cases where scaling is always a no-op
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1053
        for(int i=0; i < identityTestCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1054
            for(int j=0; j < manyScalingFactors.length; j++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1055
                failures += testScalbCase(identityTestCases[i],
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1056
                                          manyScalingFactors[j],
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1057
                                          identityTestCases[i]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1058
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1059
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1060
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1061
        // Test cases where result is 0.0 or infinity due to magnitude
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1062
        // of the scaling factor
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1063
        for(int i=0; i < someTestCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1064
            for(int j=0; j < manyScalingFactors.length; j++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1065
                int scaleFactor = manyScalingFactors[j];
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1066
                if (Math.abs(scaleFactor) >= MAX_SCALE) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1067
                    float value = someTestCases[i];
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1068
                    failures+=testScalbCase(value,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1069
                                            scaleFactor,
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 5506
diff changeset
  1070
                                            Math.copySign( (scaleFactor>0?infinityF:0.0f), value) );
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1071
                }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1072
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1073
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1074
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1075
        // Test cases that could be done with one floating-point
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1076
        // multiply.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1077
        for(int i=0; i < someTestCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1078
            for(int j=0; j < oneMultiplyScalingFactors.length; j++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1079
                int scaleFactor = oneMultiplyScalingFactors[j];
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1080
                    float value = someTestCases[i];
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1081
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1082
                    failures+=testScalbCase(value,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1083
                                            scaleFactor,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1084
                                            value*powerOfTwoF(scaleFactor));
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1085
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1086
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1087
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1088
        // Create 2^MAX_EXPONENT
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1089
        float twoToTheMaxExp = 1.0f; // 2^0
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1090
        for(int i = 0; i < Float.MAX_EXPONENT; i++)
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1091
            twoToTheMaxExp *=2.0f;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1092
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1093
        // Scale-up subnormal values until they all overflow
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1094
        for(int i=0; i < subnormalTestCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1095
            float scale = 1.0f; // 2^j
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1096
            float value = subnormalTestCases[i];
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1097
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1098
            for(int j=Float.MAX_EXPONENT*2; j < MAX_SCALE; j++) { // MAX_SCALE -1 should cause overflow
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1099
                int scaleFactor = j;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1100
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1101
                failures+=testScalbCase(value,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1102
                                        scaleFactor,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1103
                                        (Tests.ilogb(value) +j > Float.MAX_EXPONENT ) ?
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 5506
diff changeset
  1104
                                        Math.copySign(infinityF, value) : // overflow
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1105
                                        // calculate right answer
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1106
                                        twoToTheMaxExp*(twoToTheMaxExp*(scale*value)) );
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1107
                scale*=2.0f;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1108
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1109
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1110
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1111
        // Scale down a large number until it underflows.  By scaling
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1112
        // down MAX_NORMALmm, the first subnormal result will be exact
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1113
        // but the next one will round -- all those results can be
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1114
        // checked by halving a separate value in the loop.  Actually,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1115
        // we can keep halving and checking until the product is zero
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1116
        // since:
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1117
        //
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1118
        // 1. If the scalb of MAX_VALUEmm is subnormal and *not* exact
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1119
        // it will round *up*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1120
        //
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1121
        // 2. When rounding first occurs in the expected product, it
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1122
        // too rounds up, to 2^-MAX_EXPONENT.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1123
        //
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1124
        // Halving expected after rounding happends to give the same
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1125
        // result as the scalb operation.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1126
        float expected = Float_MAX_VALUEmm *0.5f;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1127
        for(int i = -1; i > -MAX_SCALE; i--) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1128
            failures+=testScalbCase(Float_MAX_VALUEmm, i, expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1129
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1130
            expected *= 0.5f;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1131
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1132
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1133
        // Tricky rounding tests:
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1134
        // Scale down a large number into subnormal range such that if
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1135
        // scalb is being implemented with multiple floating-point
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1136
        // multiplies, the value would round twice if the multiplies
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1137
        // were done in the wrong order.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1138
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1139
        float value = 0x8.0000bP-5f;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1140
        expected = 0x1.00001p-129f;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1141
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1142
        for(int i = 0; i < 129; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1143
            failures+=testScalbCase(value,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1144
                                    -127-i,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1145
                                    expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1146
            value *=2.0f;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1147
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1148
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1149
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1150
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1151
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1152
    static int testScalbCase(double value, int scale_factor, double expected) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1153
        int failures=0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1154
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1155
        failures+=Tests.test("Math.scalb(double,int)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1156
                             value, scale_factor,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1157
                             Math.scalb(value, scale_factor), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1158
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1159
        failures+=Tests.test("Math.scalb(double,int)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1160
                             -value, scale_factor,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1161
                             Math.scalb(-value, scale_factor), -expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1162
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1163
        failures+=Tests.test("StrictMath.scalb(double,int)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1164
                             value, scale_factor,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1165
                             StrictMath.scalb(value, scale_factor), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1166
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1167
        failures+=Tests.test("StrictMath.scalb(double,int)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1168
                             -value, scale_factor,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1169
                             StrictMath.scalb(-value, scale_factor), -expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1170
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1171
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1172
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1173
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1174
    public static int testDoubleScalb() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1175
        int failures=0;
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1176
        int MAX_SCALE = Double.MAX_EXPONENT + -Double.MIN_EXPONENT +
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1177
                        DoubleConsts.SIGNIFICAND_WIDTH + 1;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1178
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1179
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1180
        // Arguments x, where scalb(x,n) is x for any n.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1181
        double [] identityTestCases = {NaNd,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1182
                                      -0.0,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1183
                                      +0.0,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1184
                                      infinityD,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1185
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1186
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1187
        double [] subnormalTestCases = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1188
            Double.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1189
            3.0d*Double.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1190
            Double_MAX_SUBNORMALmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1191
            Double_MAX_SUBNORMAL
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1192
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1193
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1194
        double [] someTestCases = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1195
            Double.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1196
            3.0d*Double.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1197
            Double_MAX_SUBNORMALmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1198
            Double_MAX_SUBNORMAL,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1199
            Double.MIN_NORMAL,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1200
            1.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1201
            2.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1202
            3.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1203
            Math.PI,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1204
            Double_MAX_VALUEmm,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1205
            Double.MAX_VALUE
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1206
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1207
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1208
        int [] oneMultiplyScalingFactors = {
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1209
            Double.MIN_EXPONENT,
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1210
            Double.MIN_EXPONENT+1,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1211
            -3,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1212
            -2,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1213
            -1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1214
            0,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1215
            1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1216
            2,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1217
            3,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1218
            Double.MAX_EXPONENT-1,
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1219
            Double.MAX_EXPONENT
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1220
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1221
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1222
        int [] manyScalingFactors = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1223
            Integer.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1224
            Integer.MIN_VALUE+1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1225
            -MAX_SCALE -1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1226
            -MAX_SCALE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1227
            -MAX_SCALE+1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1228
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1229
            2*Double.MIN_EXPONENT-1,      // -2045
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1230
            2*Double.MIN_EXPONENT,        // -2044
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1231
            2*Double.MIN_EXPONENT+1,      // -2043
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1232
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1233
            Double.MIN_EXPONENT,          // -1022
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1234
            Double.MIN_EXPONENT - DoubleConsts.SIGNIFICAND_WIDTH,
22634
9c18aebe9229 8033416: Remove sun.misc.FpUtils
darcy
parents: 10608
diff changeset
  1235
            DoubleConsts.MIN_SUB_EXPONENT,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1236
            -Double.MAX_EXPONENT,         // -1023
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1237
            Double.MIN_EXPONENT,          // -1022
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1238
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1239
            -2,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1240
            -1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1241
            0,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1242
            1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1243
            2,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1244
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1245
            Double.MAX_EXPONENT-1,        // 1022
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1246
            Double.MAX_EXPONENT,          // 1023
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1247
            Double.MAX_EXPONENT+1,        // 1024
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1248
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1249
            2*Double.MAX_EXPONENT-1,      // 2045
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1250
            2*Double.MAX_EXPONENT,        // 2046
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1251
            2*Double.MAX_EXPONENT+1,      // 2047
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1252
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1253
            MAX_SCALE-1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1254
            MAX_SCALE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1255
            MAX_SCALE+1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1256
            Integer.MAX_VALUE-1,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1257
            Integer.MAX_VALUE
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1258
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1259
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1260
        // Test cases where scaling is always a no-op
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1261
        for(int i=0; i < identityTestCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1262
            for(int j=0; j < manyScalingFactors.length; j++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1263
                failures += testScalbCase(identityTestCases[i],
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1264
                                          manyScalingFactors[j],
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1265
                                          identityTestCases[i]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1266
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1267
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1268
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1269
        // Test cases where result is 0.0 or infinity due to magnitude
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1270
        // of the scaling factor
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1271
        for(int i=0; i < someTestCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1272
            for(int j=0; j < manyScalingFactors.length; j++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1273
                int scaleFactor = manyScalingFactors[j];
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1274
                if (Math.abs(scaleFactor) >= MAX_SCALE) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1275
                    double value = someTestCases[i];
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1276
                    failures+=testScalbCase(value,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1277
                                            scaleFactor,
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 5506
diff changeset
  1278
                                            Math.copySign( (scaleFactor>0?infinityD:0.0), value) );
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1279
                }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1280
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1281
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1282
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1283
        // Test cases that could be done with one floating-point
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1284
        // multiply.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1285
        for(int i=0; i < someTestCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1286
            for(int j=0; j < oneMultiplyScalingFactors.length; j++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1287
                int scaleFactor = oneMultiplyScalingFactors[j];
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1288
                    double value = someTestCases[i];
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1289
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1290
                    failures+=testScalbCase(value,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1291
                                            scaleFactor,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1292
                                            value*powerOfTwoD(scaleFactor));
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1293
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1294
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1295
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1296
        // Create 2^MAX_EXPONENT
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1297
        double twoToTheMaxExp = 1.0; // 2^0
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1298
        for(int i = 0; i < Double.MAX_EXPONENT; i++)
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1299
            twoToTheMaxExp *=2.0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1300
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1301
        // Scale-up subnormal values until they all overflow
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1302
        for(int i=0; i < subnormalTestCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1303
            double scale = 1.0; // 2^j
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1304
            double value = subnormalTestCases[i];
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1305
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1306
            for(int j=Double.MAX_EXPONENT*2; j < MAX_SCALE; j++) { // MAX_SCALE -1 should cause overflow
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1307
                int scaleFactor = j;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1308
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1309
                failures+=testScalbCase(value,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1310
                                        scaleFactor,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1311
                                        (Tests.ilogb(value) +j > Double.MAX_EXPONENT ) ?
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 5506
diff changeset
  1312
                                        Math.copySign(infinityD, value) : // overflow
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1313
                                        // calculate right answer
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1314
                                        twoToTheMaxExp*(twoToTheMaxExp*(scale*value)) );
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1315
                scale*=2.0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1316
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1317
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1318
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1319
        // Scale down a large number until it underflows.  By scaling
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1320
        // down MAX_NORMALmm, the first subnormal result will be exact
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1321
        // but the next one will round -- all those results can be
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1322
        // checked by halving a separate value in the loop.  Actually,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1323
        // we can keep halving and checking until the product is zero
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1324
        // since:
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1325
        //
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1326
        // 1. If the scalb of MAX_VALUEmm is subnormal and *not* exact
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1327
        // it will round *up*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1328
        //
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1329
        // 2. When rounding first occurs in the expected product, it
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1330
        // too rounds up, to 2^-MAX_EXPONENT.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1331
        //
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1332
        // Halving expected after rounding happends to give the same
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1333
        // result as the scalb operation.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1334
        double expected = Double_MAX_VALUEmm *0.5f;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1335
        for(int i = -1; i > -MAX_SCALE; i--) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1336
            failures+=testScalbCase(Double_MAX_VALUEmm, i, expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1337
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1338
            expected *= 0.5;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1339
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1340
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1341
        // Tricky rounding tests:
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1342
        // Scale down a large number into subnormal range such that if
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1343
        // scalb is being implemented with multiple floating-point
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1344
        // multiplies, the value would round twice if the multiplies
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1345
        // were done in the wrong order.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1346
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1347
        double value = 0x1.000000000000bP-1;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1348
        expected     = 0x0.2000000000001P-1022;
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1349
        for(int i = 0; i < Double.MAX_EXPONENT+2; i++) {
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1350
            failures+=testScalbCase(value,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1351
                                    -1024-i,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1352
                                    expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1353
            value *=2.0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1354
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1355
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1356
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1357
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1358
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1359
    /* ************************* ulp tests ******************************* */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1360
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1361
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1362
    /*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1363
     * Test Math.ulp and StrictMath.ulp with +d and -d.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1364
     */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1365
    static int testUlpCase(float f, float expected) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1366
        float minus_f = -f;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1367
        int failures=0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1368
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1369
        failures+=Tests.test("Math.ulp(float)", f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1370
                             Math.ulp(f), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1371
        failures+=Tests.test("Math.ulp(float)", minus_f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1372
                             Math.ulp(minus_f), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1373
        failures+=Tests.test("StrictMath.ulp(float)", f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1374
                             StrictMath.ulp(f), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1375
        failures+=Tests.test("StrictMath.ulp(float)", minus_f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1376
                             StrictMath.ulp(minus_f), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1377
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1378
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1379
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1380
    static int testUlpCase(double d, double expected) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1381
        double minus_d = -d;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1382
        int failures=0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1383
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1384
        failures+=Tests.test("Math.ulp(double)", d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1385
                             Math.ulp(d), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1386
        failures+=Tests.test("Math.ulp(double)", minus_d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1387
                             Math.ulp(minus_d), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1388
        failures+=Tests.test("StrictMath.ulp(double)", d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1389
                             StrictMath.ulp(d), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1390
        failures+=Tests.test("StrictMath.ulp(double)", minus_d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1391
                             StrictMath.ulp(minus_d), expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1392
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1393
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1394
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1395
    public static int testFloatUlp() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1396
        int failures = 0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1397
        float [] specialValues = {NaNf,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1398
                                  Float.POSITIVE_INFINITY,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1399
                                  +0.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1400
                                  +1.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1401
                                  +2.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1402
                                  +16.0f,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1403
                                  +Float.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1404
                                  +Float_MAX_SUBNORMAL,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1405
                                  +Float.MIN_NORMAL,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1406
                                  +Float.MAX_VALUE
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1407
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1408
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1409
        float [] specialResults = {NaNf,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1410
                                   Float.POSITIVE_INFINITY,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1411
                                   Float.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1412
                                   powerOfTwoF(-23),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1413
                                   powerOfTwoF(-22),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1414
                                   powerOfTwoF(-19),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1415
                                   Float.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1416
                                   Float.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1417
                                   Float.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1418
                                   powerOfTwoF(104)
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1419
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1420
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1421
        // Special value tests
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1422
        for(int i = 0; i < specialValues.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1423
            failures += testUlpCase(specialValues[i], specialResults[i]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1424
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1425
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1426
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1427
        // Normal exponent tests
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1428
        for(int i = Float.MIN_EXPONENT; i <= Float.MAX_EXPONENT; i++) {
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1429
            float expected;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1430
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1431
            // Create power of two
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1432
            float po2 = powerOfTwoF(i);
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 5506
diff changeset
  1433
            expected = Math.scalb(1.0f, i - (FloatConsts.SIGNIFICAND_WIDTH-1));
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1434
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1435
            failures += testUlpCase(po2, expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1436
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1437
            // Generate some random bit patterns for the significand
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1438
            for(int j = 0; j < 10; j++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1439
                int randSignif = rand.nextInt();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1440
                float randFloat;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1441
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1442
                randFloat = Float.intBitsToFloat( // Exponent
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1443
                                                 (Float.floatToIntBits(po2)&
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1444
                                                  (~FloatConsts.SIGNIF_BIT_MASK)) |
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1445
                                                 // Significand
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1446
                                                 (randSignif &
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1447
                                                  FloatConsts.SIGNIF_BIT_MASK) );
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1448
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1449
                failures += testUlpCase(randFloat, expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1450
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1451
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1452
            if (i > Float.MIN_EXPONENT) {
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 5506
diff changeset
  1453
                float po2minus = Math.nextAfter(po2,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1454
                                                   Float.NEGATIVE_INFINITY);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1455
                failures += testUlpCase(po2minus, expected/2.0f);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1456
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1457
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1458
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1459
        // Subnormal tests
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1460
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1461
        /*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1462
         * Start with MIN_VALUE, left shift, test high value, low
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1463
         * values, and random in between.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1464
         *
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1465
         * Use nextAfter to calculate, high value of previous binade,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1466
         * loop count i will indicate how many random bits, if any are
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1467
         * needed.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1468
         */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1469
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1470
        float top=Float.MIN_VALUE;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1471
        for( int i = 1;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1472
            i < FloatConsts.SIGNIFICAND_WIDTH;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1473
            i++, top *= 2.0f) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1474
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1475
            failures += testUlpCase(top, Float.MIN_VALUE);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1476
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1477
            // Test largest value in next smaller binade
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1478
            if (i >= 3) {// (i == 1) would test 0.0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1479
                         // (i == 2) would just retest MIN_VALUE
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 5506
diff changeset
  1480
                testUlpCase(Math.nextAfter(top, 0.0f),
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1481
                            Float.MIN_VALUE);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1482
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1483
                if( i >= 10) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1484
                    // create a bit mask with (i-1) 1's in the low order
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1485
                    // bits
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1486
                    int mask = ~((~0)<<(i-1));
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1487
                    float randFloat = Float.intBitsToFloat( // Exponent
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1488
                                                 Float.floatToIntBits(top) |
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1489
                                                 // Significand
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1490
                                                 (rand.nextInt() & mask ) ) ;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1491
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1492
                    failures += testUlpCase(randFloat, Float.MIN_VALUE);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1493
                }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1494
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1495
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1496
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1497
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1498
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1499
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1500
    public static int testDoubleUlp() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1501
        int failures = 0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1502
        double [] specialValues = {NaNd,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1503
                                  Double.POSITIVE_INFINITY,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1504
                                  +0.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1505
                                  +1.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1506
                                  +2.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1507
                                  +16.0d,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1508
                                  +Double.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1509
                                  +Double_MAX_SUBNORMAL,
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1510
                                  +Double.MIN_NORMAL,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1511
                                  +Double.MAX_VALUE
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1512
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1513
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1514
        double [] specialResults = {NaNf,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1515
                                   Double.POSITIVE_INFINITY,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1516
                                   Double.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1517
                                   powerOfTwoD(-52),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1518
                                   powerOfTwoD(-51),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1519
                                   powerOfTwoD(-48),
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1520
                                   Double.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1521
                                   Double.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1522
                                   Double.MIN_VALUE,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1523
                                   powerOfTwoD(971)
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1524
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1525
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1526
        // Special value tests
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1527
        for(int i = 0; i < specialValues.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1528
            failures += testUlpCase(specialValues[i], specialResults[i]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1529
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1530
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1531
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1532
        // Normal exponent tests
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1533
        for(int i = Double.MIN_EXPONENT; i <= Double.MAX_EXPONENT; i++) {
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1534
            double expected;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1535
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1536
            // Create power of two
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1537
            double po2 = powerOfTwoD(i);
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 5506
diff changeset
  1538
            expected = Math.scalb(1.0, i - (DoubleConsts.SIGNIFICAND_WIDTH-1));
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1539
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1540
            failures += testUlpCase(po2, expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1541
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1542
            // Generate some random bit patterns for the significand
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1543
            for(int j = 0; j < 10; j++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1544
                long randSignif = rand.nextLong();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1545
                double randDouble;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1546
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1547
                randDouble = Double.longBitsToDouble( // Exponent
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1548
                                                 (Double.doubleToLongBits(po2)&
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1549
                                                  (~DoubleConsts.SIGNIF_BIT_MASK)) |
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1550
                                                 // Significand
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1551
                                                 (randSignif &
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1552
                                                  DoubleConsts.SIGNIF_BIT_MASK) );
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1553
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1554
                failures += testUlpCase(randDouble, expected);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1555
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1556
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1557
            if (i > Double.MIN_EXPONENT) {
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 5506
diff changeset
  1558
                double po2minus = Math.nextAfter(po2,
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1559
                                                    Double.NEGATIVE_INFINITY);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1560
                failures += testUlpCase(po2minus, expected/2.0f);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1561
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1562
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1563
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1564
        // Subnormal tests
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1565
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1566
        /*
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1567
         * Start with MIN_VALUE, left shift, test high value, low
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1568
         * values, and random in between.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1569
         *
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1570
         * Use nextAfter to calculate, high value of previous binade,
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1571
         * loop count i will indicate how many random bits, if any are
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1572
         * needed.
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1573
         */
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1574
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1575
        double top=Double.MIN_VALUE;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1576
        for( int i = 1;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1577
            i < DoubleConsts.SIGNIFICAND_WIDTH;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1578
            i++, top *= 2.0f) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1579
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1580
            failures += testUlpCase(top, Double.MIN_VALUE);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1581
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1582
            // Test largest value in next smaller binade
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1583
            if (i >= 3) {// (i == 1) would test 0.0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1584
                         // (i == 2) would just retest MIN_VALUE
10598
efd29b4b3e67 7091682: Move sun.misc.FpUtils code into java.lang.Math
darcy
parents: 5506
diff changeset
  1585
                testUlpCase(Math.nextAfter(top, 0.0f),
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1586
                            Double.MIN_VALUE);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1587
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1588
                if( i >= 10) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1589
                    // create a bit mask with (i-1) 1's in the low order
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1590
                    // bits
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1591
                    int mask = ~((~0)<<(i-1));
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1592
                    double randDouble = Double.longBitsToDouble( // Exponent
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1593
                                                 Double.doubleToLongBits(top) |
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1594
                                                 // Significand
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1595
                                                 (rand.nextLong() & mask ) ) ;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1596
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1597
                    failures += testUlpCase(randDouble, Double.MIN_VALUE);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1598
                }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1599
            }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1600
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1601
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1602
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1603
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1604
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1605
    public static int testFloatSignum() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1606
        int failures = 0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1607
        float testCases [][] = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1608
            {NaNf,                      NaNf},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1609
            {-infinityF,                -1.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1610
            {-Float.MAX_VALUE,          -1.0f},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1611
            {-Float.MIN_NORMAL,         -1.0f},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1612
            {-1.0f,                     -1.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1613
            {-2.0f,                     -1.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1614
            {-Float_MAX_SUBNORMAL,      -1.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1615
            {-Float.MIN_VALUE,          -1.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1616
            {-0.0f,                     -0.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1617
            {+0.0f,                     +0.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1618
            {Float.MIN_VALUE,            1.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1619
            {Float_MAX_SUBNORMALmm,      1.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1620
            {Float_MAX_SUBNORMAL,        1.0f},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1621
            {Float.MIN_NORMAL,           1.0f},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1622
            {1.0f,                       1.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1623
            {2.0f,                       1.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1624
            {Float_MAX_VALUEmm,          1.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1625
            {Float.MAX_VALUE,            1.0f},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1626
            {infinityF,                  1.0f}
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1627
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1628
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1629
        for(int i = 0; i < testCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1630
            failures+=Tests.test("Math.signum(float)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1631
                                 testCases[i][0], Math.signum(testCases[i][0]), testCases[i][1]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1632
            failures+=Tests.test("StrictMath.signum(float)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1633
                                 testCases[i][0], StrictMath.signum(testCases[i][0]), testCases[i][1]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1634
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1635
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1636
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1637
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1638
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1639
    public static int testDoubleSignum() {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1640
        int failures = 0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1641
        double testCases [][] = {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1642
            {NaNd,                      NaNd},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1643
            {-infinityD,                -1.0},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1644
            {-Double.MAX_VALUE,         -1.0},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1645
            {-Double.MIN_NORMAL,        -1.0},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1646
            {-1.0,                      -1.0},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1647
            {-2.0,                      -1.0},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1648
            {-Double_MAX_SUBNORMAL,     -1.0},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1649
            {-Double.MIN_VALUE,         -1.0d},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1650
            {-0.0d,                     -0.0d},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1651
            {+0.0d,                     +0.0d},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1652
            {Double.MIN_VALUE,           1.0},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1653
            {Double_MAX_SUBNORMALmm,     1.0},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1654
            {Double_MAX_SUBNORMAL,       1.0},
26197
1bb6b68b87cd 8042003: Update java/lang/Math tests to eliminate dependency on sun.misc.DoubleConsts and sun.misc.FloatConsts
mchung
parents: 22634
diff changeset
  1655
            {Double.MIN_NORMAL,          1.0},
1826
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1656
            {1.0,                        1.0},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1657
            {2.0,                        1.0},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1658
            {Double_MAX_VALUEmm,         1.0},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1659
            {Double.MAX_VALUE,           1.0},
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1660
            {infinityD,                  1.0}
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1661
        };
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1662
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1663
        for(int i = 0; i < testCases.length; i++) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1664
            failures+=Tests.test("Math.signum(double)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1665
                                 testCases[i][0], Math.signum(testCases[i][0]), testCases[i][1]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1666
            failures+=Tests.test("StrictMath.signum(double)",
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1667
                                 testCases[i][0], StrictMath.signum(testCases[i][0]), testCases[i][1]);
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1668
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1669
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1670
        return failures;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1671
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1672
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1673
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1674
    public static void main(String argv[]) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1675
        int failures = 0;
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1676
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1677
        failures += testFloatGetExponent();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1678
        failures += testDoubleGetExponent();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1679
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1680
        failures += testFloatNextAfter();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1681
        failures += testDoubleNextAfter();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1682
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1683
        failures += testFloatNextUp();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1684
        failures += testDoubleNextUp();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1685
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1686
        failures += testFloatNextDown();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1687
        failures += testDoubleNextDown();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1688
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1689
        failures += testFloatBooleanMethods();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1690
        failures += testDoubleBooleanMethods();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1691
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1692
        failures += testFloatCopySign();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1693
        failures += testDoubleCopySign();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1694
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1695
        failures += testFloatScalb();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1696
        failures += testDoubleScalb();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1697
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1698
        failures += testFloatUlp();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1699
        failures += testDoubleUlp();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1700
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1701
        failures += testFloatSignum();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1702
        failures += testDoubleSignum();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1703
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1704
        if (failures > 0) {
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1705
            System.err.println("Testing the recommended functions incurred "
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1706
                               + failures + " failures.");
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1707
            throw new RuntimeException();
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1708
        }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1709
    }
39d505a353e8 6601457: Move wrapper class tests from closed to open
darcy
parents:
diff changeset
  1710
}