Java Code Examples for sun.misc.FpUtils

The following examples show how to use sun.misc.FpUtils. These examples are extracted from open source projects. 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 Project: dragonwell8_jdk   Source File: Tests.java    License: 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 Project: dragonwell8_jdk   Source File: Tests.java    License: 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 3
Source Project: TencentKona-8   Source File: Tests.java    License: 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 4
Source Project: TencentKona-8   Source File: Tests.java    License: 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 5
Source Project: native-obfuscator   Source File: Tests.java    License: 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 6
Source Project: native-obfuscator   Source File: Tests.java    License: 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 Project: native-obfuscator   Source File: Tests.java    License: 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 8
Source Project: native-obfuscator   Source File: Tests.java    License: 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 9
Source Project: native-obfuscator   Source File: Tests.java    License: 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 10
Source Project: native-obfuscator   Source File: Tests.java    License: 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 11
Source Project: native-obfuscator   Source File: Tests.java    License: 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 12
Source Project: native-obfuscator   Source File: Tests.java    License: 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 13
Source Project: native-obfuscator   Source File: Tests.java    License: 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 14
Source Project: native-obfuscator   Source File: Tests.java    License: 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 15
Source Project: native-obfuscator   Source File: Tests.java    License: 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 16
Source Project: native-obfuscator   Source File: Tests.java    License: 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 17
Source Project: jdk8u60   Source File: Tests.java    License: 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 18
Source Project: jdk8u60   Source File: Tests.java    License: 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 19
Source Project: openjdk-jdk8u   Source File: Tests.java    License: 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 20
Source Project: openjdk-jdk8u   Source File: Tests.java    License: 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 Project: openjdk-jdk8u-backup   Source File: Tests.java    License: 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 Project: openjdk-jdk8u-backup   Source File: Tests.java    License: 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 Project: jdk8u-jdk   Source File: Tests.java    License: 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 Project: jdk8u-jdk   Source File: Tests.java    License: 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 Project: hottub   Source File: Tests.java    License: 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 Project: hottub   Source File: Tests.java    License: 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 Project: openjdk-8-source   Source File: Tests.java    License: 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 Project: openjdk-8-source   Source File: Tests.java    License: 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 Project: openjdk-8   Source File: Tests.java    License: 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 Project: openjdk-8   Source File: Tests.java    License: 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;
}