sun.misc.FpUtils Java Examples

The following examples show how to use sun.misc.FpUtils. 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: Tests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static int testUlpCore(double result, double expected, double ulps) {
    // We assume we won't be unlucky and have an inexact expected
    // be nextDown(2^i) when 2^i would be the correctly rounded
    // answer.  This would cause the ulp size to be half as large
    // as it should be, doubling the measured error).

    if (Double.compare(expected, result) == 0) {
        return 0;   // result and expected are equivalent
    } else {
        if( ulps == 0.0) {
            // Equivalent results required but not found
            return 1;
        } else {
            double difference = expected - result;
            if (FpUtils.isUnordered(expected, result) ||
                Double.isNaN(difference) ||
                // fail if greater than or unordered
                !(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
                return 1;
            }
            else
                return 0;
        }
    }
}
 
Example #2
Source File: Tests.java    From native-obfuscator with GNU General Public License v3.0 6 votes vote down vote up
static int testUlpCore(double result, double expected, double ulps) {
    // We assume we won't be unlucky and have an inexact expected
    // be nextDown(2^i) when 2^i would be the correctly rounded
    // answer.  This would cause the ulp size to be half as large
    // as it should be, doubling the measured error).

    if (Double.compare(expected, result) == 0) {
        return 0;   // result and expected are equivalent
    } else {
        if( ulps == 0.0) {
            // Equivalent results required but not found
            return 1;
        } else {
            double difference = expected - result;
            if (FpUtils.isUnordered(expected, result) ||
                Double.isNaN(difference) ||
                // fail if greater than or unordered
                !(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
                return 1;
            }
            else
                return 0;
        }
    }
}
 
Example #3
Source File: Tests.java    From native-obfuscator with GNU General Public License v3.0 6 votes vote down vote up
public static int testTolerance(String testName, double input,
                                double result, double expected, double tolerance) {
    if (Double.compare(expected, result ) != 0) {
        double difference = expected - result;
        if (FpUtils.isUnordered(expected, result) ||
            Double.isNaN(difference) ||
            // fail if greater than or unordered
            !(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
            System.err.println("Failure for " + testName + ":\n" +
                               "\tFor input " + input    + "\t(" + toHexString(input) + ")\n" +
                               "\texpected  " + expected + "\t(" + toHexString(expected) + ")\n" +
                               "\tgot       " + result   + "\t(" + toHexString(result) + ");\n" +
                               "\tdifference greater than tolerance 10^-" + tolerance);
            return 1;
        }
        return 0;
    }
    else
        return 0;
}
 
Example #4
Source File: Tests.java    From native-obfuscator with GNU General Public License v3.0 6 votes vote down vote up
static int testUlpCore(double result, double expected, double ulps) {
    // We assume we won't be unlucky and have an inexact expected
    // be nextDown(2^i) when 2^i would be the correctly rounded
    // answer.  This would cause the ulp size to be half as large
    // as it should be, doubling the measured error).

    if (Double.compare(expected, result) == 0) {
        return 0;   // result and expected are equivalent
    } else {
        if( ulps == 0.0) {
            // Equivalent results required but not found
            return 1;
        } else {
            double difference = expected - result;
            if (FpUtils.isUnordered(expected, result) ||
                Double.isNaN(difference) ||
                // fail if greater than or unordered
                !(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
                return 1;
            }
            else
                return 0;
        }
    }
}
 
Example #5
Source File: Tests.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static int testTolerance(String testName, double input,
                                double result, double expected, double tolerance) {
    if (Double.compare(expected, result ) != 0) {
        double difference = expected - result;
        if (FpUtils.isUnordered(expected, result) ||
            Double.isNaN(difference) ||
            // fail if greater than or unordered
            !(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
            System.err.println("Failure for " + testName + ":\n" +
                               "\tFor input " + input    + "\t(" + toHexString(input) + ")\n" +
                               "\texpected  " + expected + "\t(" + toHexString(expected) + ")\n" +
                               "\tgot       " + result   + "\t(" + toHexString(result) + ");\n" +
                               "\tdifference greater than tolerance 10^-" + tolerance);
            return 1;
        }
        return 0;
    }
    else
        return 0;
}
 
Example #6
Source File: Tests.java    From native-obfuscator with GNU General Public License v3.0 6 votes vote down vote up
public static int testTolerance(String testName, double input,
                                double result, double expected, double tolerance) {
    if (Double.compare(expected, result ) != 0) {
        double difference = expected - result;
        if (FpUtils.isUnordered(expected, result) ||
            Double.isNaN(difference) ||
            // fail if greater than or unordered
            !(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
            System.err.println("Failure for " + testName + ":\n" +
                               "\tFor input " + input    + "\t(" + toHexString(input) + ")\n" +
                               "\texpected  " + expected + "\t(" + toHexString(expected) + ")\n" +
                               "\tgot       " + result   + "\t(" + toHexString(result) + ");\n" +
                               "\tdifference greater than tolerance 10^-" + tolerance);
            return 1;
        }
        return 0;
    }
    else
        return 0;
}
 
Example #7
Source File: Tests.java    From native-obfuscator with GNU General Public License v3.0 6 votes vote down vote up
public static int testTolerance(String testName, double input,
                                double result, double expected, double tolerance) {
    if (Double.compare(expected, result ) != 0) {
        double difference = expected - result;
        if (FpUtils.isUnordered(expected, result) ||
            Double.isNaN(difference) ||
            // fail if greater than or unordered
            !(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
            System.err.println("Failure for " + testName + ":\n" +
                               "\tFor input " + input    + "\t(" + toHexString(input) + ")\n" +
                               "\texpected  " + expected + "\t(" + toHexString(expected) + ")\n" +
                               "\tgot       " + result   + "\t(" + toHexString(result) + ");\n" +
                               "\tdifference greater than tolerance 10^-" + tolerance);
            return 1;
        }
        return 0;
    }
    else
        return 0;
}
 
Example #8
Source File: Tests.java    From native-obfuscator with GNU General Public License v3.0 6 votes vote down vote up
static int testUlpCore(double result, double expected, double ulps) {
    // We assume we won't be unlucky and have an inexact expected
    // be nextDown(2^i) when 2^i would be the correctly rounded
    // answer.  This would cause the ulp size to be half as large
    // as it should be, doubling the measured error).

    if (Double.compare(expected, result) == 0) {
        return 0;   // result and expected are equivalent
    } else {
        if( ulps == 0.0) {
            // Equivalent results required but not found
            return 1;
        } else {
            double difference = expected - result;
            if (FpUtils.isUnordered(expected, result) ||
                Double.isNaN(difference) ||
                // fail if greater than or unordered
                !(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
                return 1;
            }
            else
                return 0;
        }
    }
}
 
Example #9
Source File: Tests.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static int testTolerance(String testName, double input,
                                double result, double expected, double tolerance) {
    if (Double.compare(expected, result ) != 0) {
        double difference = expected - result;
        if (FpUtils.isUnordered(expected, result) ||
            Double.isNaN(difference) ||
            // fail if greater than or unordered
            !(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
            System.err.println("Failure for " + testName + ":\n" +
                               "\tFor input " + input    + "\t(" + toHexString(input) + ")\n" +
                               "\texpected  " + expected + "\t(" + toHexString(expected) + ")\n" +
                               "\tgot       " + result   + "\t(" + toHexString(result) + ");\n" +
                               "\tdifference greater than tolerance 10^-" + tolerance);
            return 1;
        }
        return 0;
    }
    else
        return 0;
}
 
Example #10
Source File: Tests.java    From native-obfuscator with GNU General Public License v3.0 6 votes vote down vote up
static int testUlpCore(double result, double expected, double ulps) {
    // We assume we won't be unlucky and have an inexact expected
    // be nextDown(2^i) when 2^i would be the correctly rounded
    // answer.  This would cause the ulp size to be half as large
    // as it should be, doubling the measured error).

    if (Double.compare(expected, result) == 0) {
        return 0;   // result and expected are equivalent
    } else {
        if( ulps == 0.0) {
            // Equivalent results required but not found
            return 1;
        } else {
            double difference = expected - result;
            if (FpUtils.isUnordered(expected, result) ||
                Double.isNaN(difference) ||
                // fail if greater than or unordered
                !(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
                return 1;
            }
            else
                return 0;
        }
    }
}
 
Example #11
Source File: Tests.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static int testUlpCore(double result, double expected, double ulps) {
    // We assume we won't be unlucky and have an inexact expected
    // be nextDown(2^i) when 2^i would be the correctly rounded
    // answer.  This would cause the ulp size to be half as large
    // as it should be, doubling the measured error).

    if (Double.compare(expected, result) == 0) {
        return 0;   // result and expected are equivalent
    } else {
        if( ulps == 0.0) {
            // Equivalent results required but not found
            return 1;
        } else {
            double difference = expected - result;
            if (FpUtils.isUnordered(expected, result) ||
                Double.isNaN(difference) ||
                // fail if greater than or unordered
                !(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
                return 1;
            }
            else
                return 0;
        }
    }
}
 
Example #12
Source File: Tests.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static int testUlpCore(double result, double expected, double ulps) {
    // We assume we won't be unlucky and have an inexact expected
    // be nextDown(2^i) when 2^i would be the correctly rounded
    // answer.  This would cause the ulp size to be half as large
    // as it should be, doubling the measured error).

    if (Double.compare(expected, result) == 0) {
        return 0;   // result and expected are equivalent
    } else {
        if( ulps == 0.0) {
            // Equivalent results required but not found
            return 1;
        } else {
            double difference = expected - result;
            if (FpUtils.isUnordered(expected, result) ||
                Double.isNaN(difference) ||
                // fail if greater than or unordered
                !(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
                return 1;
            }
            else
                return 0;
        }
    }
}
 
Example #13
Source File: Tests.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static int testTolerance(String testName, double input,
                                double result, double expected, double tolerance) {
    if (Double.compare(expected, result ) != 0) {
        double difference = expected - result;
        if (FpUtils.isUnordered(expected, result) ||
            Double.isNaN(difference) ||
            // fail if greater than or unordered
            !(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
            System.err.println("Failure for " + testName + ":\n" +
                               "\tFor input " + input    + "\t(" + toHexString(input) + ")\n" +
                               "\texpected  " + expected + "\t(" + toHexString(expected) + ")\n" +
                               "\tgot       " + result   + "\t(" + toHexString(result) + ");\n" +
                               "\tdifference greater than tolerance 10^-" + tolerance);
            return 1;
        }
        return 0;
    }
    else
        return 0;
}
 
Example #14
Source File: Tests.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static int testUlpCore(double result, double expected, double ulps) {
    // We assume we won't be unlucky and have an inexact expected
    // be nextDown(2^i) when 2^i would be the correctly rounded
    // answer.  This would cause the ulp size to be half as large
    // as it should be, doubling the measured error).

    if (Double.compare(expected, result) == 0) {
        return 0;   // result and expected are equivalent
    } else {
        if( ulps == 0.0) {
            // Equivalent results required but not found
            return 1;
        } else {
            double difference = expected - result;
            if (FpUtils.isUnordered(expected, result) ||
                Double.isNaN(difference) ||
                // fail if greater than or unordered
                !(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
                return 1;
            }
            else
                return 0;
        }
    }
}
 
Example #15
Source File: Tests.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static int testTolerance(String testName, double input,
                                double result, double expected, double tolerance) {
    if (Double.compare(expected, result ) != 0) {
        double difference = expected - result;
        if (FpUtils.isUnordered(expected, result) ||
            Double.isNaN(difference) ||
            // fail if greater than or unordered
            !(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
            System.err.println("Failure for " + testName + ":\n" +
                               "\tFor input " + input    + "\t(" + toHexString(input) + ")\n" +
                               "\texpected  " + expected + "\t(" + toHexString(expected) + ")\n" +
                               "\tgot       " + result   + "\t(" + toHexString(result) + ");\n" +
                               "\tdifference greater than tolerance 10^-" + tolerance);
            return 1;
        }
        return 0;
    }
    else
        return 0;
}
 
Example #16
Source File: Tests.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static int testUlpCore(double result, double expected, double ulps) {
    // We assume we won't be unlucky and have an inexact expected
    // be nextDown(2^i) when 2^i would be the correctly rounded
    // answer.  This would cause the ulp size to be half as large
    // as it should be, doubling the measured error).

    if (Double.compare(expected, result) == 0) {
        return 0;   // result and expected are equivalent
    } else {
        if( ulps == 0.0) {
            // Equivalent results required but not found
            return 1;
        } else {
            double difference = expected - result;
            if (FpUtils.isUnordered(expected, result) ||
                Double.isNaN(difference) ||
                // fail if greater than or unordered
                !(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
                return 1;
            }
            else
                return 0;
        }
    }
}
 
Example #17
Source File: Tests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static int testTolerance(String testName, double input,
                                double result, double expected, double tolerance) {
    if (Double.compare(expected, result ) != 0) {
        double difference = expected - result;
        if (FpUtils.isUnordered(expected, result) ||
            Double.isNaN(difference) ||
            // fail if greater than or unordered
            !(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
            System.err.println("Failure for " + testName + ":\n" +
                               "\tFor input " + input    + "\t(" + toHexString(input) + ")\n" +
                               "\texpected  " + expected + "\t(" + toHexString(expected) + ")\n" +
                               "\tgot       " + result   + "\t(" + toHexString(result) + ");\n" +
                               "\tdifference greater than tolerance 10^-" + tolerance);
            return 1;
        }
        return 0;
    }
    else
        return 0;
}
 
Example #18
Source File: Tests.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static int testUlpCore(double result, double expected, double ulps) {
    // We assume we won't be unlucky and have an inexact expected
    // be nextDown(2^i) when 2^i would be the correctly rounded
    // answer.  This would cause the ulp size to be half as large
    // as it should be, doubling the measured error).

    if (Double.compare(expected, result) == 0) {
        return 0;   // result and expected are equivalent
    } else {
        if( ulps == 0.0) {
            // Equivalent results required but not found
            return 1;
        } else {
            double difference = expected - result;
            if (FpUtils.isUnordered(expected, result) ||
                Double.isNaN(difference) ||
                // fail if greater than or unordered
                !(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
                return 1;
            }
            else
                return 0;
        }
    }
}
 
Example #19
Source File: Tests.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static int testTolerance(String testName, double input,
                                double result, double expected, double tolerance) {
    if (Double.compare(expected, result ) != 0) {
        double difference = expected - result;
        if (FpUtils.isUnordered(expected, result) ||
            Double.isNaN(difference) ||
            // fail if greater than or unordered
            !(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
            System.err.println("Failure for " + testName + ":\n" +
                               "\tFor input " + input    + "\t(" + toHexString(input) + ")\n" +
                               "\texpected  " + expected + "\t(" + toHexString(expected) + ")\n" +
                               "\tgot       " + result   + "\t(" + toHexString(result) + ");\n" +
                               "\tdifference greater than tolerance 10^-" + tolerance);
            return 1;
        }
        return 0;
    }
    else
        return 0;
}
 
Example #20
Source File: Tests.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static int testTolerance(String testName, double input,
                                double result, double expected, double tolerance) {
    if (Double.compare(expected, result ) != 0) {
        double difference = expected - result;
        if (FpUtils.isUnordered(expected, result) ||
            Double.isNaN(difference) ||
            // fail if greater than or unordered
            !(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
            System.err.println("Failure for " + testName + ":\n" +
                               "\tFor input " + input    + "\t(" + toHexString(input) + ")\n" +
                               "\texpected  " + expected + "\t(" + toHexString(expected) + ")\n" +
                               "\tgot       " + result   + "\t(" + toHexString(result) + ");\n" +
                               "\tdifference greater than tolerance 10^-" + tolerance);
            return 1;
        }
        return 0;
    }
    else
        return 0;
}
 
Example #21
Source File: Tests.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static int testUlpCore(double result, double expected, double ulps) {
    // We assume we won't be unlucky and have an inexact expected
    // be nextDown(2^i) when 2^i would be the correctly rounded
    // answer.  This would cause the ulp size to be half as large
    // as it should be, doubling the measured error).

    if (Double.compare(expected, result) == 0) {
        return 0;   // result and expected are equivalent
    } else {
        if( ulps == 0.0) {
            // Equivalent results required but not found
            return 1;
        } else {
            double difference = expected - result;
            if (FpUtils.isUnordered(expected, result) ||
                Double.isNaN(difference) ||
                // fail if greater than or unordered
                !(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
                return 1;
            }
            else
                return 0;
        }
    }
}
 
Example #22
Source File: Tests.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static int testTolerance(String testName, double input,
                                double result, double expected, double tolerance) {
    if (Double.compare(expected, result ) != 0) {
        double difference = expected - result;
        if (FpUtils.isUnordered(expected, result) ||
            Double.isNaN(difference) ||
            // fail if greater than or unordered
            !(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
            System.err.println("Failure for " + testName + ":\n" +
                               "\tFor input " + input    + "\t(" + toHexString(input) + ")\n" +
                               "\texpected  " + expected + "\t(" + toHexString(expected) + ")\n" +
                               "\tgot       " + result   + "\t(" + toHexString(result) + ");\n" +
                               "\tdifference greater than tolerance 10^-" + tolerance);
            return 1;
        }
        return 0;
    }
    else
        return 0;
}
 
Example #23
Source File: Tests.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static int testUlpCore(double result, double expected, double ulps) {
    // We assume we won't be unlucky and have an inexact expected
    // be nextDown(2^i) when 2^i would be the correctly rounded
    // answer.  This would cause the ulp size to be half as large
    // as it should be, doubling the measured error).

    if (Double.compare(expected, result) == 0) {
        return 0;   // result and expected are equivalent
    } else {
        if( ulps == 0.0) {
            // Equivalent results required but not found
            return 1;
        } else {
            double difference = expected - result;
            if (FpUtils.isUnordered(expected, result) ||
                Double.isNaN(difference) ||
                // fail if greater than or unordered
                !(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
                return 1;
            }
            else
                return 0;
        }
    }
}
 
Example #24
Source File: Tests.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static int testTolerance(String testName, double input,
                                double result, double expected, double tolerance) {
    if (Double.compare(expected, result ) != 0) {
        double difference = expected - result;
        if (FpUtils.isUnordered(expected, result) ||
            Double.isNaN(difference) ||
            // fail if greater than or unordered
            !(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
            System.err.println("Failure for " + testName + ":\n" +
                               "\tFor input " + input    + "\t(" + toHexString(input) + ")\n" +
                               "\texpected  " + expected + "\t(" + toHexString(expected) + ")\n" +
                               "\tgot       " + result   + "\t(" + toHexString(result) + ");\n" +
                               "\tdifference greater than tolerance 10^-" + tolerance);
            return 1;
        }
        return 0;
    }
    else
        return 0;
}
 
Example #25
Source File: Tests.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static int testUlpCore(double result, double expected, double ulps) {
    // We assume we won't be unlucky and have an inexact expected
    // be nextDown(2^i) when 2^i would be the correctly rounded
    // answer.  This would cause the ulp size to be half as large
    // as it should be, doubling the measured error).

    if (Double.compare(expected, result) == 0) {
        return 0;   // result and expected are equivalent
    } else {
        if( ulps == 0.0) {
            // Equivalent results required but not found
            return 1;
        } else {
            double difference = expected - result;
            if (FpUtils.isUnordered(expected, result) ||
                Double.isNaN(difference) ||
                // fail if greater than or unordered
                !(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
                return 1;
            }
            else
                return 0;
        }
    }
}
 
Example #26
Source File: Tests.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static int testTolerance(String testName, double input,
                                double result, double expected, double tolerance) {
    if (Double.compare(expected, result ) != 0) {
        double difference = expected - result;
        if (FpUtils.isUnordered(expected, result) ||
            Double.isNaN(difference) ||
            // fail if greater than or unordered
            !(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
            System.err.println("Failure for " + testName + ":\n" +
                               "\tFor input " + input    + "\t(" + toHexString(input) + ")\n" +
                               "\texpected  " + expected + "\t(" + toHexString(expected) + ")\n" +
                               "\tgot       " + result   + "\t(" + toHexString(result) + ");\n" +
                               "\tdifference greater than tolerance 10^-" + tolerance);
            return 1;
        }
        return 0;
    }
    else
        return 0;
}
 
Example #27
Source File: Tests.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static int testUlpCore(double result, double expected, double ulps) {
    // We assume we won't be unlucky and have an inexact expected
    // be nextDown(2^i) when 2^i would be the correctly rounded
    // answer.  This would cause the ulp size to be half as large
    // as it should be, doubling the measured error).

    if (Double.compare(expected, result) == 0) {
        return 0;   // result and expected are equivalent
    } else {
        if( ulps == 0.0) {
            // Equivalent results required but not found
            return 1;
        } else {
            double difference = expected - result;
            if (FpUtils.isUnordered(expected, result) ||
                Double.isNaN(difference) ||
                // fail if greater than or unordered
                !(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
                return 1;
            }
            else
                return 0;
        }
    }
}
 
Example #28
Source File: Tests.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static int testTolerance(String testName, double input,
                                double result, double expected, double tolerance) {
    if (Double.compare(expected, result ) != 0) {
        double difference = expected - result;
        if (FpUtils.isUnordered(expected, result) ||
            Double.isNaN(difference) ||
            // fail if greater than or unordered
            !(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
            System.err.println("Failure for " + testName + ":\n" +
                               "\tFor input " + input    + "\t(" + toHexString(input) + ")\n" +
                               "\texpected  " + expected + "\t(" + toHexString(expected) + ")\n" +
                               "\tgot       " + result   + "\t(" + toHexString(result) + ");\n" +
                               "\tdifference greater than tolerance 10^-" + tolerance);
            return 1;
        }
        return 0;
    }
    else
        return 0;
}
 
Example #29
Source File: Tests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
static int testUlpCore(double result, double expected, double ulps) {
    // We assume we won't be unlucky and have an inexact expected
    // be nextDown(2^i) when 2^i would be the correctly rounded
    // answer.  This would cause the ulp size to be half as large
    // as it should be, doubling the measured error).

    if (Double.compare(expected, result) == 0) {
        return 0;   // result and expected are equivalent
    } else {
        if( ulps == 0.0) {
            // Equivalent results required but not found
            return 1;
        } else {
            double difference = expected - result;
            if (FpUtils.isUnordered(expected, result) ||
                Double.isNaN(difference) ||
                // fail if greater than or unordered
                !(Math.abs( difference/Math.ulp(expected) ) <= Math.abs(ulps)) ) {
                return 1;
            }
            else
                return 0;
        }
    }
}
 
Example #30
Source File: Tests.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static int testTolerance(String testName, double input,
                                double result, double expected, double tolerance) {
    if (Double.compare(expected, result ) != 0) {
        double difference = expected - result;
        if (FpUtils.isUnordered(expected, result) ||
            Double.isNaN(difference) ||
            // fail if greater than or unordered
            !(Math.abs((difference)/expected) <= StrictMath.pow(10, -tolerance)) ) {
            System.err.println("Failure for " + testName + ":\n" +
                               "\tFor input " + input    + "\t(" + toHexString(input) + ")\n" +
                               "\texpected  " + expected + "\t(" + toHexString(expected) + ")\n" +
                               "\tgot       " + result   + "\t(" + toHexString(result) + ");\n" +
                               "\tdifference greater than tolerance 10^-" + tolerance);
            return 1;
        }
        return 0;
    }
    else
        return 0;
}