Java Code Examples for sun.misc.DoubleConsts#MIN_NORMAL

The following examples show how to use sun.misc.DoubleConsts#MIN_NORMAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IeeeRecommendedTests.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static int testDoubleNextUp() {
    int failures=0;

    /*
     * Each row of testCases represents one test case for nextUp;
     * the first column is the input and the second column is the
     * expected result.
     */
    double testCases [][] = {
        {NaNd,                      NaNd},
        {-infinityD,                -Double.MAX_VALUE},
        {-Double.MAX_VALUE,         -Double_MAX_VALUEmm},
        {-DoubleConsts.MIN_NORMAL,  -Double_MAX_SUBNORMAL},
        {-Double_MAX_SUBNORMAL,     -Double_MAX_SUBNORMALmm},
        {-Double.MIN_VALUE,         -0.0d},
        {-0.0d,                     Double.MIN_VALUE},
        {+0.0d,                     Double.MIN_VALUE},
        {Double.MIN_VALUE,          Double.MIN_VALUE*2},
        {Double_MAX_SUBNORMALmm,    Double_MAX_SUBNORMAL},
        {Double_MAX_SUBNORMAL,      DoubleConsts.MIN_NORMAL},
        {DoubleConsts.MIN_NORMAL,   DoubleConsts.MIN_NORMAL+Double.MIN_VALUE},
        {Double_MAX_VALUEmm,        Double.MAX_VALUE},
        {Double.MAX_VALUE,          infinityD},
        {infinityD,                 infinityD}
    };

    for(int i = 0; i < testCases.length; i++) {
        failures+=Tests.test("Math.nextUp(double)",
                             testCases[i][0], Math.nextUp(testCases[i][0]), testCases[i][1]);

        failures+=Tests.test("StrictMath.nextUp(double)",
                             testCases[i][0], StrictMath.nextUp(testCases[i][0]), testCases[i][1]);
    }

    return failures;
}
 
Example 2
Source File: IeeeRecommendedTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static int testDoubleNextUp() {
    int failures=0;

    /*
     * Each row of testCases represents one test case for nextUp;
     * the first column is the input and the second column is the
     * expected result.
     */
    double testCases [][] = {
        {NaNd,                      NaNd},
        {-infinityD,                -Double.MAX_VALUE},
        {-Double.MAX_VALUE,         -Double_MAX_VALUEmm},
        {-DoubleConsts.MIN_NORMAL,  -Double_MAX_SUBNORMAL},
        {-Double_MAX_SUBNORMAL,     -Double_MAX_SUBNORMALmm},
        {-Double.MIN_VALUE,         -0.0d},
        {-0.0d,                     Double.MIN_VALUE},
        {+0.0d,                     Double.MIN_VALUE},
        {Double.MIN_VALUE,          Double.MIN_VALUE*2},
        {Double_MAX_SUBNORMALmm,    Double_MAX_SUBNORMAL},
        {Double_MAX_SUBNORMAL,      DoubleConsts.MIN_NORMAL},
        {DoubleConsts.MIN_NORMAL,   DoubleConsts.MIN_NORMAL+Double.MIN_VALUE},
        {Double_MAX_VALUEmm,        Double.MAX_VALUE},
        {Double.MAX_VALUE,          infinityD},
        {infinityD,                 infinityD}
    };

    for(int i = 0; i < testCases.length; i++) {
        failures+=Tests.test("Math.nextUp(double)",
                             testCases[i][0], Math.nextUp(testCases[i][0]), testCases[i][1]);

        failures+=Tests.test("StrictMath.nextUp(double)",
                             testCases[i][0], StrictMath.nextUp(testCases[i][0]), testCases[i][1]);
    }

    return failures;
}
 
Example 3
Source File: IeeeRecommendedTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static int testDoubleNextDown() {
    int failures=0;

    /*
     * Each row of testCases represents one test case for nextDown;
     * the first column is the input and the second column is the
     * expected result.
     */
    double testCases [][] = {
        {NaNd,                      NaNd},
        {-infinityD,                -infinityD},
        {-Double.MAX_VALUE,         -infinityD},
        {-Double_MAX_VALUEmm,       -Double.MAX_VALUE},
        {-Double_MAX_SUBNORMAL,     -DoubleConsts.MIN_NORMAL},
        {-Double_MAX_SUBNORMALmm,   -Double_MAX_SUBNORMAL},
        {-0.0d,                     -Double.MIN_VALUE},
        {+0.0d,                     -Double.MIN_VALUE},
        {Double.MIN_VALUE,          0.0d},
        {Double.MIN_VALUE*2,        Double.MIN_VALUE},
        {Double_MAX_SUBNORMAL,      Double_MAX_SUBNORMALmm},
        {DoubleConsts.MIN_NORMAL,   Double_MAX_SUBNORMAL},
        {DoubleConsts.MIN_NORMAL+
         Double.MIN_VALUE,          DoubleConsts.MIN_NORMAL},
        {Double.MAX_VALUE,          Double_MAX_VALUEmm},
        {infinityD,                 Double.MAX_VALUE},
    };

    for(int i = 0; i < testCases.length; i++) {
        failures+=Tests.test("Math.nextDown(double)",
                             testCases[i][0], Math.nextDown(testCases[i][0]), testCases[i][1]);

        failures+=Tests.test("StrictMath.nextDown(double)",
                             testCases[i][0], StrictMath.nextDown(testCases[i][0]), testCases[i][1]);
    }

    return failures;
}
 
Example 4
Source File: IeeeRecommendedTests.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static int testDoubleSignum() {
    int failures = 0;
    double testCases [][] = {
        {NaNd,                      NaNd},
        {-infinityD,                -1.0},
        {-Double.MAX_VALUE,         -1.0},
        {-DoubleConsts.MIN_NORMAL,  -1.0},
        {-1.0,                      -1.0},
        {-2.0,                      -1.0},
        {-Double_MAX_SUBNORMAL,     -1.0},
        {-Double.MIN_VALUE,         -1.0d},
        {-0.0d,                     -0.0d},
        {+0.0d,                     +0.0d},
        {Double.MIN_VALUE,           1.0},
        {Double_MAX_SUBNORMALmm,     1.0},
        {Double_MAX_SUBNORMAL,       1.0},
        {DoubleConsts.MIN_NORMAL,    1.0},
        {1.0,                        1.0},
        {2.0,                        1.0},
        {Double_MAX_VALUEmm,         1.0},
        {Double.MAX_VALUE,           1.0},
        {infinityD,                  1.0}
    };

    for(int i = 0; i < testCases.length; i++) {
        failures+=Tests.test("Math.signum(double)",
                             testCases[i][0], Math.signum(testCases[i][0]), testCases[i][1]);
        failures+=Tests.test("StrictMath.signum(double)",
                             testCases[i][0], StrictMath.signum(testCases[i][0]), testCases[i][1]);
    }

    return failures;
}
 
Example 5
Source File: IeeeRecommendedTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static int testDoubleNextUp() {
    int failures=0;

    /*
     * Each row of testCases represents one test case for nextUp;
     * the first column is the input and the second column is the
     * expected result.
     */
    double testCases [][] = {
        {NaNd,                      NaNd},
        {-infinityD,                -Double.MAX_VALUE},
        {-Double.MAX_VALUE,         -Double_MAX_VALUEmm},
        {-DoubleConsts.MIN_NORMAL,  -Double_MAX_SUBNORMAL},
        {-Double_MAX_SUBNORMAL,     -Double_MAX_SUBNORMALmm},
        {-Double.MIN_VALUE,         -0.0d},
        {-0.0d,                     Double.MIN_VALUE},
        {+0.0d,                     Double.MIN_VALUE},
        {Double.MIN_VALUE,          Double.MIN_VALUE*2},
        {Double_MAX_SUBNORMALmm,    Double_MAX_SUBNORMAL},
        {Double_MAX_SUBNORMAL,      DoubleConsts.MIN_NORMAL},
        {DoubleConsts.MIN_NORMAL,   DoubleConsts.MIN_NORMAL+Double.MIN_VALUE},
        {Double_MAX_VALUEmm,        Double.MAX_VALUE},
        {Double.MAX_VALUE,          infinityD},
        {infinityD,                 infinityD}
    };

    for(int i = 0; i < testCases.length; i++) {
        failures+=Tests.test("Math.nextUp(double)",
                             testCases[i][0], Math.nextUp(testCases[i][0]), testCases[i][1]);

        failures+=Tests.test("StrictMath.nextUp(double)",
                             testCases[i][0], StrictMath.nextUp(testCases[i][0]), testCases[i][1]);
    }

    return failures;
}
 
Example 6
Source File: IeeeRecommendedTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static int testDoubleSignum() {
    int failures = 0;
    double testCases [][] = {
        {NaNd,                      NaNd},
        {-infinityD,                -1.0},
        {-Double.MAX_VALUE,         -1.0},
        {-DoubleConsts.MIN_NORMAL,  -1.0},
        {-1.0,                      -1.0},
        {-2.0,                      -1.0},
        {-Double_MAX_SUBNORMAL,     -1.0},
        {-Double.MIN_VALUE,         -1.0d},
        {-0.0d,                     -0.0d},
        {+0.0d,                     +0.0d},
        {Double.MIN_VALUE,           1.0},
        {Double_MAX_SUBNORMALmm,     1.0},
        {Double_MAX_SUBNORMAL,       1.0},
        {DoubleConsts.MIN_NORMAL,    1.0},
        {1.0,                        1.0},
        {2.0,                        1.0},
        {Double_MAX_VALUEmm,         1.0},
        {Double.MAX_VALUE,           1.0},
        {infinityD,                  1.0}
    };

    for(int i = 0; i < testCases.length; i++) {
        failures+=Tests.test("Math.signum(double)",
                             testCases[i][0], Math.signum(testCases[i][0]), testCases[i][1]);
        failures+=Tests.test("StrictMath.signum(double)",
                             testCases[i][0], StrictMath.signum(testCases[i][0]), testCases[i][1]);
    }

    return failures;
}
 
Example 7
Source File: IeeeRecommendedTests.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static int testDoubleNextAfter() {
    int failures =0;

    /*
     * Each row of the testCases matrix represents one test case
     * for nexAfter; given the input of the first two columns, the
     * result in the last column is expected.
     */
    double [][] testCases  = {
        {NaNd,              NaNd,                   NaNd},
        {NaNd,              0.0d,                   NaNd},
        {0.0d,              NaNd,                   NaNd},
        {NaNd,              infinityD,              NaNd},
        {infinityD,         NaNd,                   NaNd},

        {infinityD,         infinityD,              infinityD},
        {infinityD,         -infinityD,             Double.MAX_VALUE},
        {infinityD,         0.0d,                   Double.MAX_VALUE},

        {Double.MAX_VALUE,  infinityD,              infinityD},
        {Double.MAX_VALUE,  -infinityD,             Double_MAX_VALUEmm},
        {Double.MAX_VALUE,  Double.MAX_VALUE,       Double.MAX_VALUE},
        {Double.MAX_VALUE,  0.0d,                   Double_MAX_VALUEmm},

        {Double_MAX_VALUEmm,        Double.MAX_VALUE,       Double.MAX_VALUE},
        {Double_MAX_VALUEmm,        infinityD,              Double.MAX_VALUE},
        {Double_MAX_VALUEmm,        Double_MAX_VALUEmm,     Double_MAX_VALUEmm},

        {DoubleConsts.MIN_NORMAL,   infinityD,              DoubleConsts.MIN_NORMAL+
                                                            Double.MIN_VALUE},
        {DoubleConsts.MIN_NORMAL,   -infinityD,             Double_MAX_SUBNORMAL},
        {DoubleConsts.MIN_NORMAL,   1.0f,                   DoubleConsts.MIN_NORMAL+
                                                            Double.MIN_VALUE},
        {DoubleConsts.MIN_NORMAL,   -1.0f,                  Double_MAX_SUBNORMAL},
        {DoubleConsts.MIN_NORMAL,   DoubleConsts.MIN_NORMAL,DoubleConsts.MIN_NORMAL},

        {Double_MAX_SUBNORMAL,      DoubleConsts.MIN_NORMAL,DoubleConsts.MIN_NORMAL},
        {Double_MAX_SUBNORMAL,      Double_MAX_SUBNORMAL,   Double_MAX_SUBNORMAL},
        {Double_MAX_SUBNORMAL,      0.0d,                   Double_MAX_SUBNORMALmm},

        {Double_MAX_SUBNORMALmm,    Double_MAX_SUBNORMAL,   Double_MAX_SUBNORMAL},
        {Double_MAX_SUBNORMALmm,    0.0d,                   Double_MAX_SUBNORMALmm-Double.MIN_VALUE},
        {Double_MAX_SUBNORMALmm,    Double_MAX_SUBNORMALmm, Double_MAX_SUBNORMALmm},

        {Double.MIN_VALUE,  0.0d,                   0.0d},
        {-Double.MIN_VALUE, 0.0d,                   -0.0d},
        {Double.MIN_VALUE,  Double.MIN_VALUE,       Double.MIN_VALUE},
        {Double.MIN_VALUE,  1.0f,                   2*Double.MIN_VALUE},

        // Make sure zero behavior is tested
        {0.0d,              0.0d,                   0.0d},
        {0.0d,              -0.0d,                  -0.0d},
        {-0.0d,             0.0d,                   0.0d},
        {-0.0d,             -0.0d,                  -0.0d},
        {0.0d,              infinityD,              Double.MIN_VALUE},
        {0.0d,              -infinityD,             -Double.MIN_VALUE},
        {-0.0d,             infinityD,              Double.MIN_VALUE},
        {-0.0d,             -infinityD,             -Double.MIN_VALUE},
        {0.0d,              Double.MIN_VALUE,       Double.MIN_VALUE},
        {0.0d,              -Double.MIN_VALUE,      -Double.MIN_VALUE},
        {-0.0d,             Double.MIN_VALUE,       Double.MIN_VALUE},
        {-0.0d,             -Double.MIN_VALUE,      -Double.MIN_VALUE}
    };

    for(int i = 0; i < testCases.length; i++) {
        failures += testNextAfterCase(testCases[i][0], testCases[i][1],
                                      testCases[i][2]);
    }
    return failures;
}
 
Example 8
Source File: Rint.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) {
    int failures = 0;
    double twoToThe52 = Math.scalb(1.0, 52); // 2^52

    double [][] testCases = {
        {0.0,                               0.0},
        {Double.MIN_VALUE,                  0.0},
        {Math.nextDown(DoubleConsts.MIN_NORMAL), 0.0},
        {DoubleConsts.MIN_NORMAL,           0.0},

        {0.2,                               0.0},

        {Math.nextDown(0.5),             0.0},
        {              0.5,              0.0},
        {  Math.nextUp(0.5),             1.0},

        {0.7,                               1.0},
        {Math.nextDown(1.0),             1.0},
        {              1.0,              1.0},
        {  Math.nextUp(1.0),             1.0},

        {Math.nextDown(1.5),             1.0},
        {              1.5,              2.0},
        {  Math.nextUp(1.5),             2.0},

        {4.2,                               4.0},
        {4.5,                               4.0},
        {4.7,                               5.0},

        {7.5,                               8.0},
        {7.2,                               7.0},
        {7.7,                               8.0},

        {150000.75,                         150001.0},
        {300000.5,                          300000.0},
        {Math.nextUp(300000.5),          300001.0},
        {Math.nextDown(300000.75),       300001.0},
        {300000.75,                         300001.0},
        {Math.nextUp(300000.75),         300001.0},
        {300000.99,                         300001.0},
        {262144.75,                         262145.0}, //(2^18 ) + 0.75
        {499998.75,                         499999.0},
        {524287.75,                         524288.0}, //(2^19 -1) + 0.75
        {524288.75,                         524289.0},

        {Math.nextDown(twoToThe52),      twoToThe52},
        {twoToThe52,                        twoToThe52},
        {Math.nextUp(twoToThe52),        Math.nextUp(twoToThe52)},

        {Double.MAX_VALUE,          Double.MAX_VALUE},
        {Double.POSITIVE_INFINITY,  Double.POSITIVE_INFINITY},
        {Double.NaN,                        Double.NaN}

    };


    for(int i = 0; i < testCases.length; i++) {
        failures += testRintCase(testCases[i][0], testCases[i][1]);
    }

    // Test values throughout exponent range
    for(double d = Double.MIN_VALUE;
        d < Double.POSITIVE_INFINITY; d *= 2) {
        failures += testRintCase(d, ((d<=0.5)?0.0:d));
    }

    if (failures > 0) {
        System.err.println("Testing {Math, StrictMath}.rint incurred "
                           + failures + " failures.");
        throw new RuntimeException();
    }
}
 
Example 9
Source File: IeeeRecommendedTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static int testDoubleCopySign() {
    int failures = 0;

    // testCases[0] are logically positive numbers;
    // testCases[1] are negative numbers.
    double testCases [][] = {
        {+0.0d,
         Double.MIN_VALUE,
         Double_MAX_SUBNORMALmm,
         Double_MAX_SUBNORMAL,
         DoubleConsts.MIN_NORMAL,
         1.0d,
         3.0d,
         Double_MAX_VALUEmm,
         Double.MAX_VALUE,
         infinityD,
        },
        {-infinityD,
         -Double.MAX_VALUE,
         -3.0d,
         -1.0d,
         -DoubleConsts.MIN_NORMAL,
         -Double_MAX_SUBNORMALmm,
         -Double_MAX_SUBNORMAL,
         -Double.MIN_VALUE,
         -0.0d}
    };

    double NaNs[] = {Double.longBitsToDouble(0x7ff8000000000000L),  // "positive" NaN
                     Double.longBitsToDouble(0xfff8000000000000L),  // "negative" NaN
                     Double.longBitsToDouble(0x7FF0000000000001L),
                     Double.longBitsToDouble(0xFFF0000000000001L),
                     Double.longBitsToDouble(0x7FF8555555555555L),
                     Double.longBitsToDouble(0xFFF8555555555555L),
                     Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL),
                     Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL),
                     Double.longBitsToDouble(0x7FFDeadBeef00000L),
                     Double.longBitsToDouble(0xFFFDeadBeef00000L),
                     Double.longBitsToDouble(0x7FFCafeBabe00000L),
                     Double.longBitsToDouble(0xFFFCafeBabe00000L)};

    // Tests shared between Math and StrictMath versions
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) {
            for(int m = 0; m < testCases[i].length; m++) {
                for(int n = 0; n < testCases[j].length; n++) {
                    // copySign(magnitude, sign)
                    failures+=Tests.test("MathcopySign(double,double)",
                                         testCases[i][m],testCases[j][n],
                                         Math.copySign(testCases[i][m], testCases[j][n]),
                                         (j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );

                    failures+=Tests.test("StrictMath.copySign(double,double)",
                                         testCases[i][m],testCases[j][n],
                                         StrictMath.copySign(testCases[i][m], testCases[j][n]),
                                         (j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );
                }
            }
        }
    }

    // For Math.copySign, NaN may effectively have either sign bit
    // while for StrictMath.copySign NaNs are treated as if they
    // always have a zero sign bit (i.e. as positive numbers)
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < NaNs.length; j++) {
            for(int m = 0; m < testCases[i].length; m++) {
                // copySign(magnitude, sign)

                failures += (Math.abs(Math.copySign(testCases[i][m], NaNs[j])) ==
                             Math.abs(testCases[i][m])) ? 0:1;


                failures+=Tests.test("StrictMath.copySign(double,double)",
                                     testCases[i][m], NaNs[j],
                                     StrictMath.copySign(testCases[i][m], NaNs[j]),
                                     Math.abs(testCases[i][m]) );
            }
        }
    }


    return failures;
}
 
Example 10
Source File: Rint.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) {
    int failures = 0;
    double twoToThe52 = Math.scalb(1.0, 52); // 2^52

    double [][] testCases = {
        {0.0,                               0.0},
        {Double.MIN_VALUE,                  0.0},
        {Math.nextDown(DoubleConsts.MIN_NORMAL), 0.0},
        {DoubleConsts.MIN_NORMAL,           0.0},

        {0.2,                               0.0},

        {Math.nextDown(0.5),             0.0},
        {              0.5,              0.0},
        {  Math.nextUp(0.5),             1.0},

        {0.7,                               1.0},
        {Math.nextDown(1.0),             1.0},
        {              1.0,              1.0},
        {  Math.nextUp(1.0),             1.0},

        {Math.nextDown(1.5),             1.0},
        {              1.5,              2.0},
        {  Math.nextUp(1.5),             2.0},

        {4.2,                               4.0},
        {4.5,                               4.0},
        {4.7,                               5.0},

        {7.5,                               8.0},
        {7.2,                               7.0},
        {7.7,                               8.0},

        {150000.75,                         150001.0},
        {300000.5,                          300000.0},
        {Math.nextUp(300000.5),          300001.0},
        {Math.nextDown(300000.75),       300001.0},
        {300000.75,                         300001.0},
        {Math.nextUp(300000.75),         300001.0},
        {300000.99,                         300001.0},
        {262144.75,                         262145.0}, //(2^18 ) + 0.75
        {499998.75,                         499999.0},
        {524287.75,                         524288.0}, //(2^19 -1) + 0.75
        {524288.75,                         524289.0},

        {Math.nextDown(twoToThe52),      twoToThe52},
        {twoToThe52,                        twoToThe52},
        {Math.nextUp(twoToThe52),        Math.nextUp(twoToThe52)},

        {Double.MAX_VALUE,          Double.MAX_VALUE},
        {Double.POSITIVE_INFINITY,  Double.POSITIVE_INFINITY},
        {Double.NaN,                        Double.NaN}

    };


    for(int i = 0; i < testCases.length; i++) {
        failures += testRintCase(testCases[i][0], testCases[i][1]);
    }

    // Test values throughout exponent range
    for(double d = Double.MIN_VALUE;
        d < Double.POSITIVE_INFINITY; d *= 2) {
        failures += testRintCase(d, ((d<=0.5)?0.0:d));
    }

    if (failures > 0) {
        System.err.println("Testing {Math, StrictMath}.rint incurred "
                           + failures + " failures.");
        throw new RuntimeException();
    }
}
 
Example 11
Source File: IeeeRecommendedTests.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static int testDoubleCopySign() {
    int failures = 0;

    // testCases[0] are logically positive numbers;
    // testCases[1] are negative numbers.
    double testCases [][] = {
        {+0.0d,
         Double.MIN_VALUE,
         Double_MAX_SUBNORMALmm,
         Double_MAX_SUBNORMAL,
         DoubleConsts.MIN_NORMAL,
         1.0d,
         3.0d,
         Double_MAX_VALUEmm,
         Double.MAX_VALUE,
         infinityD,
        },
        {-infinityD,
         -Double.MAX_VALUE,
         -3.0d,
         -1.0d,
         -DoubleConsts.MIN_NORMAL,
         -Double_MAX_SUBNORMALmm,
         -Double_MAX_SUBNORMAL,
         -Double.MIN_VALUE,
         -0.0d}
    };

    double NaNs[] = {Double.longBitsToDouble(0x7ff8000000000000L),  // "positive" NaN
                     Double.longBitsToDouble(0xfff8000000000000L),  // "negative" NaN
                     Double.longBitsToDouble(0x7FF0000000000001L),
                     Double.longBitsToDouble(0xFFF0000000000001L),
                     Double.longBitsToDouble(0x7FF8555555555555L),
                     Double.longBitsToDouble(0xFFF8555555555555L),
                     Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL),
                     Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL),
                     Double.longBitsToDouble(0x7FFDeadBeef00000L),
                     Double.longBitsToDouble(0xFFFDeadBeef00000L),
                     Double.longBitsToDouble(0x7FFCafeBabe00000L),
                     Double.longBitsToDouble(0xFFFCafeBabe00000L)};

    // Tests shared between Math and StrictMath versions
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) {
            for(int m = 0; m < testCases[i].length; m++) {
                for(int n = 0; n < testCases[j].length; n++) {
                    // copySign(magnitude, sign)
                    failures+=Tests.test("MathcopySign(double,double)",
                                         testCases[i][m],testCases[j][n],
                                         Math.copySign(testCases[i][m], testCases[j][n]),
                                         (j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );

                    failures+=Tests.test("StrictMath.copySign(double,double)",
                                         testCases[i][m],testCases[j][n],
                                         StrictMath.copySign(testCases[i][m], testCases[j][n]),
                                         (j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );
                }
            }
        }
    }

    // For Math.copySign, NaN may effectively have either sign bit
    // while for StrictMath.copySign NaNs are treated as if they
    // always have a zero sign bit (i.e. as positive numbers)
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < NaNs.length; j++) {
            for(int m = 0; m < testCases[i].length; m++) {
                // copySign(magnitude, sign)

                failures += (Math.abs(Math.copySign(testCases[i][m], NaNs[j])) ==
                             Math.abs(testCases[i][m])) ? 0:1;


                failures+=Tests.test("StrictMath.copySign(double,double)",
                                     testCases[i][m], NaNs[j],
                                     StrictMath.copySign(testCases[i][m], NaNs[j]),
                                     Math.abs(testCases[i][m]) );
            }
        }
    }


    return failures;
}
 
Example 12
Source File: IeeeRecommendedTests.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static int testDoubleNextAfter() {
    int failures =0;

    /*
     * Each row of the testCases matrix represents one test case
     * for nexAfter; given the input of the first two columns, the
     * result in the last column is expected.
     */
    double [][] testCases  = {
        {NaNd,              NaNd,                   NaNd},
        {NaNd,              0.0d,                   NaNd},
        {0.0d,              NaNd,                   NaNd},
        {NaNd,              infinityD,              NaNd},
        {infinityD,         NaNd,                   NaNd},

        {infinityD,         infinityD,              infinityD},
        {infinityD,         -infinityD,             Double.MAX_VALUE},
        {infinityD,         0.0d,                   Double.MAX_VALUE},

        {Double.MAX_VALUE,  infinityD,              infinityD},
        {Double.MAX_VALUE,  -infinityD,             Double_MAX_VALUEmm},
        {Double.MAX_VALUE,  Double.MAX_VALUE,       Double.MAX_VALUE},
        {Double.MAX_VALUE,  0.0d,                   Double_MAX_VALUEmm},

        {Double_MAX_VALUEmm,        Double.MAX_VALUE,       Double.MAX_VALUE},
        {Double_MAX_VALUEmm,        infinityD,              Double.MAX_VALUE},
        {Double_MAX_VALUEmm,        Double_MAX_VALUEmm,     Double_MAX_VALUEmm},

        {DoubleConsts.MIN_NORMAL,   infinityD,              DoubleConsts.MIN_NORMAL+
                                                            Double.MIN_VALUE},
        {DoubleConsts.MIN_NORMAL,   -infinityD,             Double_MAX_SUBNORMAL},
        {DoubleConsts.MIN_NORMAL,   1.0f,                   DoubleConsts.MIN_NORMAL+
                                                            Double.MIN_VALUE},
        {DoubleConsts.MIN_NORMAL,   -1.0f,                  Double_MAX_SUBNORMAL},
        {DoubleConsts.MIN_NORMAL,   DoubleConsts.MIN_NORMAL,DoubleConsts.MIN_NORMAL},

        {Double_MAX_SUBNORMAL,      DoubleConsts.MIN_NORMAL,DoubleConsts.MIN_NORMAL},
        {Double_MAX_SUBNORMAL,      Double_MAX_SUBNORMAL,   Double_MAX_SUBNORMAL},
        {Double_MAX_SUBNORMAL,      0.0d,                   Double_MAX_SUBNORMALmm},

        {Double_MAX_SUBNORMALmm,    Double_MAX_SUBNORMAL,   Double_MAX_SUBNORMAL},
        {Double_MAX_SUBNORMALmm,    0.0d,                   Double_MAX_SUBNORMALmm-Double.MIN_VALUE},
        {Double_MAX_SUBNORMALmm,    Double_MAX_SUBNORMALmm, Double_MAX_SUBNORMALmm},

        {Double.MIN_VALUE,  0.0d,                   0.0d},
        {-Double.MIN_VALUE, 0.0d,                   -0.0d},
        {Double.MIN_VALUE,  Double.MIN_VALUE,       Double.MIN_VALUE},
        {Double.MIN_VALUE,  1.0f,                   2*Double.MIN_VALUE},

        // Make sure zero behavior is tested
        {0.0d,              0.0d,                   0.0d},
        {0.0d,              -0.0d,                  -0.0d},
        {-0.0d,             0.0d,                   0.0d},
        {-0.0d,             -0.0d,                  -0.0d},
        {0.0d,              infinityD,              Double.MIN_VALUE},
        {0.0d,              -infinityD,             -Double.MIN_VALUE},
        {-0.0d,             infinityD,              Double.MIN_VALUE},
        {-0.0d,             -infinityD,             -Double.MIN_VALUE},
        {0.0d,              Double.MIN_VALUE,       Double.MIN_VALUE},
        {0.0d,              -Double.MIN_VALUE,      -Double.MIN_VALUE},
        {-0.0d,             Double.MIN_VALUE,       Double.MIN_VALUE},
        {-0.0d,             -Double.MIN_VALUE,      -Double.MIN_VALUE}
    };

    for(int i = 0; i < testCases.length; i++) {
        failures += testNextAfterCase(testCases[i][0], testCases[i][1],
                                      testCases[i][2]);
    }
    return failures;
}
 
Example 13
Source File: Rint.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) {
    int failures = 0;
    double twoToThe52 = Math.scalb(1.0, 52); // 2^52

    double [][] testCases = {
        {0.0,                               0.0},
        {Double.MIN_VALUE,                  0.0},
        {Math.nextDown(DoubleConsts.MIN_NORMAL), 0.0},
        {DoubleConsts.MIN_NORMAL,           0.0},

        {0.2,                               0.0},

        {Math.nextDown(0.5),             0.0},
        {              0.5,              0.0},
        {  Math.nextUp(0.5),             1.0},

        {0.7,                               1.0},
        {Math.nextDown(1.0),             1.0},
        {              1.0,              1.0},
        {  Math.nextUp(1.0),             1.0},

        {Math.nextDown(1.5),             1.0},
        {              1.5,              2.0},
        {  Math.nextUp(1.5),             2.0},

        {4.2,                               4.0},
        {4.5,                               4.0},
        {4.7,                               5.0},

        {7.5,                               8.0},
        {7.2,                               7.0},
        {7.7,                               8.0},

        {150000.75,                         150001.0},
        {300000.5,                          300000.0},
        {Math.nextUp(300000.5),          300001.0},
        {Math.nextDown(300000.75),       300001.0},
        {300000.75,                         300001.0},
        {Math.nextUp(300000.75),         300001.0},
        {300000.99,                         300001.0},
        {262144.75,                         262145.0}, //(2^18 ) + 0.75
        {499998.75,                         499999.0},
        {524287.75,                         524288.0}, //(2^19 -1) + 0.75
        {524288.75,                         524289.0},

        {Math.nextDown(twoToThe52),      twoToThe52},
        {twoToThe52,                        twoToThe52},
        {Math.nextUp(twoToThe52),        Math.nextUp(twoToThe52)},

        {Double.MAX_VALUE,          Double.MAX_VALUE},
        {Double.POSITIVE_INFINITY,  Double.POSITIVE_INFINITY},
        {Double.NaN,                        Double.NaN}

    };


    for(int i = 0; i < testCases.length; i++) {
        failures += testRintCase(testCases[i][0], testCases[i][1]);
    }

    // Test values throughout exponent range
    for(double d = Double.MIN_VALUE;
        d < Double.POSITIVE_INFINITY; d *= 2) {
        failures += testRintCase(d, ((d<=0.5)?0.0:d));
    }

    if (failures > 0) {
        System.err.println("Testing {Math, StrictMath}.rint incurred "
                           + failures + " failures.");
        throw new RuntimeException();
    }
}
 
Example 14
Source File: Rint.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) {
    int failures = 0;
    double twoToThe52 = Math.scalb(1.0, 52); // 2^52

    double [][] testCases = {
        {0.0,                               0.0},
        {Double.MIN_VALUE,                  0.0},
        {Math.nextDown(DoubleConsts.MIN_NORMAL), 0.0},
        {DoubleConsts.MIN_NORMAL,           0.0},

        {0.2,                               0.0},

        {Math.nextDown(0.5),             0.0},
        {              0.5,              0.0},
        {  Math.nextUp(0.5),             1.0},

        {0.7,                               1.0},
        {Math.nextDown(1.0),             1.0},
        {              1.0,              1.0},
        {  Math.nextUp(1.0),             1.0},

        {Math.nextDown(1.5),             1.0},
        {              1.5,              2.0},
        {  Math.nextUp(1.5),             2.0},

        {4.2,                               4.0},
        {4.5,                               4.0},
        {4.7,                               5.0},

        {7.5,                               8.0},
        {7.2,                               7.0},
        {7.7,                               8.0},

        {150000.75,                         150001.0},
        {300000.5,                          300000.0},
        {Math.nextUp(300000.5),          300001.0},
        {Math.nextDown(300000.75),       300001.0},
        {300000.75,                         300001.0},
        {Math.nextUp(300000.75),         300001.0},
        {300000.99,                         300001.0},
        {262144.75,                         262145.0}, //(2^18 ) + 0.75
        {499998.75,                         499999.0},
        {524287.75,                         524288.0}, //(2^19 -1) + 0.75
        {524288.75,                         524289.0},

        {Math.nextDown(twoToThe52),      twoToThe52},
        {twoToThe52,                        twoToThe52},
        {Math.nextUp(twoToThe52),        Math.nextUp(twoToThe52)},

        {Double.MAX_VALUE,          Double.MAX_VALUE},
        {Double.POSITIVE_INFINITY,  Double.POSITIVE_INFINITY},
        {Double.NaN,                        Double.NaN}

    };


    for(int i = 0; i < testCases.length; i++) {
        failures += testRintCase(testCases[i][0], testCases[i][1]);
    }

    // Test values throughout exponent range
    for(double d = Double.MIN_VALUE;
        d < Double.POSITIVE_INFINITY; d *= 2) {
        failures += testRintCase(d, ((d<=0.5)?0.0:d));
    }

    if (failures > 0) {
        System.err.println("Testing {Math, StrictMath}.rint incurred "
                           + failures + " failures.");
        throw new RuntimeException();
    }
}
 
Example 15
Source File: IeeeRecommendedTests.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static int testDoubleBooleanMethods() {
    int failures = 0;
    boolean result = false;

    double testCases [] = {
        NaNd,
        -infinityD,
        infinityD,
        -Double.MAX_VALUE,
        -3.0d,
        -1.0d,
        -DoubleConsts.MIN_NORMAL,
        -Double_MAX_SUBNORMALmm,
        -Double_MAX_SUBNORMAL,
        -Double.MIN_VALUE,
        -0.0d,
        +0.0d,
        Double.MIN_VALUE,
        Double_MAX_SUBNORMALmm,
        Double_MAX_SUBNORMAL,
        DoubleConsts.MIN_NORMAL,
        1.0d,
        3.0d,
        Double_MAX_VALUEmm,
        Double.MAX_VALUE
    };

    for(int i = 0; i < testCases.length; i++) {
        // isNaN
        failures+=Tests.test("FpUtils.isNaN(double)", testCases[i],
                             FpUtils.isNaN(testCases[i]), (i ==0));

        // isFinite
        failures+=Tests.test("Double.isFinite(double)", testCases[i],
                             Double.isFinite(testCases[i]), (i >= 3));

        // isInfinite
        failures+=Tests.test("FpUtils.isInfinite(double)", testCases[i],
                             FpUtils.isInfinite(testCases[i]), (i==1 || i==2));

        // isUnorderd
        for(int j = 0; j < testCases.length; j++) {
            failures+=Tests.test("FpUtils.isUnordered(double, double)", testCases[i],testCases[j],
                                 FpUtils.isUnordered(testCases[i],testCases[j]), (i==0 || j==0));
        }
    }

    return failures;
}
 
Example 16
Source File: IeeeRecommendedTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static int testDoubleCopySign() {
    int failures = 0;

    // testCases[0] are logically positive numbers;
    // testCases[1] are negative numbers.
    double testCases [][] = {
        {+0.0d,
         Double.MIN_VALUE,
         Double_MAX_SUBNORMALmm,
         Double_MAX_SUBNORMAL,
         DoubleConsts.MIN_NORMAL,
         1.0d,
         3.0d,
         Double_MAX_VALUEmm,
         Double.MAX_VALUE,
         infinityD,
        },
        {-infinityD,
         -Double.MAX_VALUE,
         -3.0d,
         -1.0d,
         -DoubleConsts.MIN_NORMAL,
         -Double_MAX_SUBNORMALmm,
         -Double_MAX_SUBNORMAL,
         -Double.MIN_VALUE,
         -0.0d}
    };

    double NaNs[] = {Double.longBitsToDouble(0x7ff8000000000000L),  // "positive" NaN
                     Double.longBitsToDouble(0xfff8000000000000L),  // "negative" NaN
                     Double.longBitsToDouble(0x7FF0000000000001L),
                     Double.longBitsToDouble(0xFFF0000000000001L),
                     Double.longBitsToDouble(0x7FF8555555555555L),
                     Double.longBitsToDouble(0xFFF8555555555555L),
                     Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL),
                     Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL),
                     Double.longBitsToDouble(0x7FFDeadBeef00000L),
                     Double.longBitsToDouble(0xFFFDeadBeef00000L),
                     Double.longBitsToDouble(0x7FFCafeBabe00000L),
                     Double.longBitsToDouble(0xFFFCafeBabe00000L)};

    // Tests shared between Math and StrictMath versions
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) {
            for(int m = 0; m < testCases[i].length; m++) {
                for(int n = 0; n < testCases[j].length; n++) {
                    // copySign(magnitude, sign)
                    failures+=Tests.test("MathcopySign(double,double)",
                                         testCases[i][m],testCases[j][n],
                                         Math.copySign(testCases[i][m], testCases[j][n]),
                                         (j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );

                    failures+=Tests.test("StrictMath.copySign(double,double)",
                                         testCases[i][m],testCases[j][n],
                                         StrictMath.copySign(testCases[i][m], testCases[j][n]),
                                         (j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );
                }
            }
        }
    }

    // For Math.copySign, NaN may effectively have either sign bit
    // while for StrictMath.copySign NaNs are treated as if they
    // always have a zero sign bit (i.e. as positive numbers)
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < NaNs.length; j++) {
            for(int m = 0; m < testCases[i].length; m++) {
                // copySign(magnitude, sign)

                failures += (Math.abs(Math.copySign(testCases[i][m], NaNs[j])) ==
                             Math.abs(testCases[i][m])) ? 0:1;


                failures+=Tests.test("StrictMath.copySign(double,double)",
                                     testCases[i][m], NaNs[j],
                                     StrictMath.copySign(testCases[i][m], NaNs[j]),
                                     Math.abs(testCases[i][m]) );
            }
        }
    }


    return failures;
}
 
Example 17
Source File: Rint.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) {
    int failures = 0;
    double twoToThe52 = Math.scalb(1.0, 52); // 2^52

    double [][] testCases = {
        {0.0,                               0.0},
        {Double.MIN_VALUE,                  0.0},
        {Math.nextDown(DoubleConsts.MIN_NORMAL), 0.0},
        {DoubleConsts.MIN_NORMAL,           0.0},

        {0.2,                               0.0},

        {Math.nextDown(0.5),             0.0},
        {              0.5,              0.0},
        {  Math.nextUp(0.5),             1.0},

        {0.7,                               1.0},
        {Math.nextDown(1.0),             1.0},
        {              1.0,              1.0},
        {  Math.nextUp(1.0),             1.0},

        {Math.nextDown(1.5),             1.0},
        {              1.5,              2.0},
        {  Math.nextUp(1.5),             2.0},

        {4.2,                               4.0},
        {4.5,                               4.0},
        {4.7,                               5.0},

        {7.5,                               8.0},
        {7.2,                               7.0},
        {7.7,                               8.0},

        {150000.75,                         150001.0},
        {300000.5,                          300000.0},
        {Math.nextUp(300000.5),          300001.0},
        {Math.nextDown(300000.75),       300001.0},
        {300000.75,                         300001.0},
        {Math.nextUp(300000.75),         300001.0},
        {300000.99,                         300001.0},
        {262144.75,                         262145.0}, //(2^18 ) + 0.75
        {499998.75,                         499999.0},
        {524287.75,                         524288.0}, //(2^19 -1) + 0.75
        {524288.75,                         524289.0},

        {Math.nextDown(twoToThe52),      twoToThe52},
        {twoToThe52,                        twoToThe52},
        {Math.nextUp(twoToThe52),        Math.nextUp(twoToThe52)},

        {Double.MAX_VALUE,          Double.MAX_VALUE},
        {Double.POSITIVE_INFINITY,  Double.POSITIVE_INFINITY},
        {Double.NaN,                        Double.NaN}

    };


    for(int i = 0; i < testCases.length; i++) {
        failures += testRintCase(testCases[i][0], testCases[i][1]);
    }

    // Test values throughout exponent range
    for(double d = Double.MIN_VALUE;
        d < Double.POSITIVE_INFINITY; d *= 2) {
        failures += testRintCase(d, ((d<=0.5)?0.0:d));
    }

    if (failures > 0) {
        System.err.println("Testing {Math, StrictMath}.rint incurred "
                           + failures + " failures.");
        throw new RuntimeException();
    }
}
 
Example 18
Source File: Rint.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String args[]) {
    int failures = 0;
    double twoToThe52 = Math.scalb(1.0, 52); // 2^52

    double [][] testCases = {
        {0.0,                               0.0},
        {Double.MIN_VALUE,                  0.0},
        {Math.nextDown(DoubleConsts.MIN_NORMAL), 0.0},
        {DoubleConsts.MIN_NORMAL,           0.0},

        {0.2,                               0.0},

        {Math.nextDown(0.5),             0.0},
        {              0.5,              0.0},
        {  Math.nextUp(0.5),             1.0},

        {0.7,                               1.0},
        {Math.nextDown(1.0),             1.0},
        {              1.0,              1.0},
        {  Math.nextUp(1.0),             1.0},

        {Math.nextDown(1.5),             1.0},
        {              1.5,              2.0},
        {  Math.nextUp(1.5),             2.0},

        {4.2,                               4.0},
        {4.5,                               4.0},
        {4.7,                               5.0},

        {7.5,                               8.0},
        {7.2,                               7.0},
        {7.7,                               8.0},

        {150000.75,                         150001.0},
        {300000.5,                          300000.0},
        {Math.nextUp(300000.5),          300001.0},
        {Math.nextDown(300000.75),       300001.0},
        {300000.75,                         300001.0},
        {Math.nextUp(300000.75),         300001.0},
        {300000.99,                         300001.0},
        {262144.75,                         262145.0}, //(2^18 ) + 0.75
        {499998.75,                         499999.0},
        {524287.75,                         524288.0}, //(2^19 -1) + 0.75
        {524288.75,                         524289.0},

        {Math.nextDown(twoToThe52),      twoToThe52},
        {twoToThe52,                        twoToThe52},
        {Math.nextUp(twoToThe52),        Math.nextUp(twoToThe52)},

        {Double.MAX_VALUE,          Double.MAX_VALUE},
        {Double.POSITIVE_INFINITY,  Double.POSITIVE_INFINITY},
        {Double.NaN,                        Double.NaN}

    };


    for(int i = 0; i < testCases.length; i++) {
        failures += testRintCase(testCases[i][0], testCases[i][1]);
    }

    // Test values throughout exponent range
    for(double d = Double.MIN_VALUE;
        d < Double.POSITIVE_INFINITY; d *= 2) {
        failures += testRintCase(d, ((d<=0.5)?0.0:d));
    }

    if (failures > 0) {
        System.err.println("Testing {Math, StrictMath}.rint incurred "
                           + failures + " failures.");
        throw new RuntimeException();
    }
}
 
Example 19
Source File: IeeeRecommendedTests.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static int testDoubleCopySign() {
    int failures = 0;

    // testCases[0] are logically positive numbers;
    // testCases[1] are negative numbers.
    double testCases [][] = {
        {+0.0d,
         Double.MIN_VALUE,
         Double_MAX_SUBNORMALmm,
         Double_MAX_SUBNORMAL,
         DoubleConsts.MIN_NORMAL,
         1.0d,
         3.0d,
         Double_MAX_VALUEmm,
         Double.MAX_VALUE,
         infinityD,
        },
        {-infinityD,
         -Double.MAX_VALUE,
         -3.0d,
         -1.0d,
         -DoubleConsts.MIN_NORMAL,
         -Double_MAX_SUBNORMALmm,
         -Double_MAX_SUBNORMAL,
         -Double.MIN_VALUE,
         -0.0d}
    };

    double NaNs[] = {Double.longBitsToDouble(0x7ff8000000000000L),  // "positive" NaN
                     Double.longBitsToDouble(0xfff8000000000000L),  // "negative" NaN
                     Double.longBitsToDouble(0x7FF0000000000001L),
                     Double.longBitsToDouble(0xFFF0000000000001L),
                     Double.longBitsToDouble(0x7FF8555555555555L),
                     Double.longBitsToDouble(0xFFF8555555555555L),
                     Double.longBitsToDouble(0x7FFFFFFFFFFFFFFFL),
                     Double.longBitsToDouble(0xFFFFFFFFFFFFFFFFL),
                     Double.longBitsToDouble(0x7FFDeadBeef00000L),
                     Double.longBitsToDouble(0xFFFDeadBeef00000L),
                     Double.longBitsToDouble(0x7FFCafeBabe00000L),
                     Double.longBitsToDouble(0xFFFCafeBabe00000L)};

    // Tests shared between Math and StrictMath versions
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) {
            for(int m = 0; m < testCases[i].length; m++) {
                for(int n = 0; n < testCases[j].length; n++) {
                    // copySign(magnitude, sign)
                    failures+=Tests.test("MathcopySign(double,double)",
                                         testCases[i][m],testCases[j][n],
                                         Math.copySign(testCases[i][m], testCases[j][n]),
                                         (j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );

                    failures+=Tests.test("StrictMath.copySign(double,double)",
                                         testCases[i][m],testCases[j][n],
                                         StrictMath.copySign(testCases[i][m], testCases[j][n]),
                                         (j==0?1.0f:-1.0f)*Math.abs(testCases[i][m]) );
                }
            }
        }
    }

    // For Math.copySign, NaN may effectively have either sign bit
    // while for StrictMath.copySign NaNs are treated as if they
    // always have a zero sign bit (i.e. as positive numbers)
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < NaNs.length; j++) {
            for(int m = 0; m < testCases[i].length; m++) {
                // copySign(magnitude, sign)

                failures += (Math.abs(Math.copySign(testCases[i][m], NaNs[j])) ==
                             Math.abs(testCases[i][m])) ? 0:1;


                failures+=Tests.test("StrictMath.copySign(double,double)",
                                     testCases[i][m], NaNs[j],
                                     StrictMath.copySign(testCases[i][m], NaNs[j]),
                                     Math.abs(testCases[i][m]) );
            }
        }
    }


    return failures;
}
 
Example 20
Source File: IeeeRecommendedTests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static int testDoubleBooleanMethods() {
    int failures = 0;
    boolean result = false;

    double testCases [] = {
        NaNd,
        -infinityD,
        infinityD,
        -Double.MAX_VALUE,
        -3.0d,
        -1.0d,
        -DoubleConsts.MIN_NORMAL,
        -Double_MAX_SUBNORMALmm,
        -Double_MAX_SUBNORMAL,
        -Double.MIN_VALUE,
        -0.0d,
        +0.0d,
        Double.MIN_VALUE,
        Double_MAX_SUBNORMALmm,
        Double_MAX_SUBNORMAL,
        DoubleConsts.MIN_NORMAL,
        1.0d,
        3.0d,
        Double_MAX_VALUEmm,
        Double.MAX_VALUE
    };

    for(int i = 0; i < testCases.length; i++) {
        // isNaN
        failures+=Tests.test("FpUtils.isNaN(double)", testCases[i],
                             FpUtils.isNaN(testCases[i]), (i ==0));

        // isFinite
        failures+=Tests.test("Double.isFinite(double)", testCases[i],
                             Double.isFinite(testCases[i]), (i >= 3));

        // isInfinite
        failures+=Tests.test("FpUtils.isInfinite(double)", testCases[i],
                             FpUtils.isInfinite(testCases[i]), (i==1 || i==2));

        // isUnorderd
        for(int j = 0; j < testCases.length; j++) {
            failures+=Tests.test("FpUtils.isUnordered(double, double)", testCases[i],testCases[j],
                                 FpUtils.isUnordered(testCases[i],testCases[j]), (i==0 || j==0));
        }
    }

    return failures;
}