--- old/make/mapfiles/libjava/mapfile-vers 2016-12-15 12:13:36.959083091 -0800 +++ new/make/mapfiles/libjava/mapfile-vers 2016-12-15 12:13:36.647083076 -0800 @@ -150,7 +150,6 @@ Java_java_lang_StrictMath_atan; Java_java_lang_StrictMath_atan2; Java_java_lang_StrictMath_cos; - Java_java_lang_StrictMath_exp; Java_java_lang_StrictMath_log; Java_java_lang_StrictMath_log10; Java_java_lang_StrictMath_sin; --- old/src/java.base/share/classes/java/lang/FdLibm.java 2016-12-15 12:13:37.791083131 -0800 +++ new/src/java.base/share/classes/java/lang/FdLibm.java 2016-12-15 12:13:37.419083113 -0800 @@ -96,7 +96,8 @@ */ private static double __HI(double x, int high) { long transX = Double.doubleToRawLongBits(x); - return Double.longBitsToDouble((transX & 0x0000_0000_FFFF_FFFFL)|( ((long)high)) << 32 ); + return Double.longBitsToDouble((transX & 0x0000_0000_FFFF_FFFFL) | + ( ((long)high)) << 32 ); } /** @@ -580,4 +581,151 @@ return s * z; } } + + /** + * Returns the exponential of x. + * + * Method + * 1. Argument reduction: + * Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658. + * Given x, find r and integer k such that + * + * x = k*ln2 + r, |r| <= 0.5*ln2. + * + * Here r will be represented as r = hi-lo for better + * accuracy. + * + * 2. Approximation of exp(r) by a special rational function on + * the interval [0,0.34658]: + * Write + * R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ... + * We use a special Reme algorithm on [0,0.34658] to generate + * a polynomial of degree 5 to approximate R. The maximum error + * of this polynomial approximation is bounded by 2**-59. In + * other words, + * R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5 + * (where z=r*r, and the values of P1 to P5 are listed below) + * and + * | 5 | -59 + * | 2.0+P1*z+...+P5*z - R(z) | <= 2 + * | | + * The computation of exp(r) thus becomes + * 2*r + * exp(r) = 1 + ------- + * R - r + * r*R1(r) + * = 1 + r + ----------- (for better accuracy) + * 2 - R1(r) + * where + * 2 4 10 + * R1(r) = r - (P1*r + P2*r + ... + P5*r ). + * + * 3. Scale back to obtain exp(x): + * From step 1, we have + * exp(x) = 2^k * exp(r) + * + * Special cases: + * exp(INF) is INF, exp(NaN) is NaN; + * exp(-INF) is 0, and + * for finite argument, only exp(0)=1 is exact. + * + * Accuracy: + * according to an error analysis, the error is always less than + * 1 ulp (unit in the last place). + * + * Misc. info. + * For IEEE double + * if x > 7.09782712893383973096e+02 then exp(x) overflow + * if x < -7.45133219101941108420e+02 then exp(x) underflow + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + static class Exp { + private static final double one = 1.0; + private static final double[] halF = {0.5, -0.5,}; + private static final double huge = 1.0e+300; + private static final double twom1000= 9.33263618503218878990e-302; /* 2**-1000=0x01700000,0*/ + private static final double o_threshold= 7.09782712893383973096e+02; /* 0x40862E42, 0xFEFA39EF */ + private static final double u_threshold= -7.45133219101941108420e+02; /* 0xc0874910, 0xD52D3051 */ + private static final double[] ln2HI ={ 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */ + -6.93147180369123816490e-01}; /* 0xbfe62e42, 0xfee00000 */ + private static final double[] ln2LO ={ 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */ + -1.90821492927058770002e-10,}; /* 0xbdea39ef, 0x35793c76 */ + private static final double invln2 = 1.44269504088896338700e+00; /* 0x3ff71547, 0x652b82fe */ + private static final double P1 = 1.66666666666666019037e-01; /* 0x3FC55555, 0x5555553E */ + private static final double P2 = -2.77777777770155933842e-03; /* 0xBF66C16C, 0x16BEBD93 */ + private static final double P3 = 6.61375632143793436117e-05; /* 0x3F11566A, 0xAF25DE2C */ + private static final double P4 = -1.65339022054652515390e-06; /* 0xBEBBBD41, 0xC5D26BF1 */ + private static final double P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */ + + // should be able to forgo strictfp due to controlled over/underflow + public static strictfp double compute(double x) { + double y; + double hi = 0.0; + double lo = 0.0; + double c; + double t; + int k = 0; + int xsb; + /*unsigned*/ int hx; + + hx = __HI(x); /* high word of x */ + xsb = (hx >> 31) & 1; /* sign bit of x */ + hx &= 0x7fffffff; /* high word of |x| */ + + /* filter out non-finite argument */ + if (hx >= 0x40862E42) { /* if |x| >= 709.78... */ + if (hx >= 0x7ff00000) { + if (((hx & 0xfffff) | __LO(x)) != 0) + return x + x; /* NaN */ + else + return (xsb == 0) ? x : 0.0; /* exp(+-inf) = {inf, 0} */ + } + if (x > o_threshold) + return huge * huge; /* overflow */ + if (x < u_threshold) // unsigned compare needed here? + return twom1000 * twom1000; /* underflow */ + } + + /* argument reduction */ + if (hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ + if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ + hi = x - ln2HI[xsb]; + lo=ln2LO[xsb]; + k = 1 - xsb - xsb; + } else { + k = (int)(invln2 * x + halF[xsb]); + t = k; + hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */ + lo = t*ln2LO[0]; + } + x = hi - lo; + } else if (hx < 0x3e300000) { /* when |x|<2**-28 */ + if (huge + x > one) + return one + x;/* trigger inexact */ + } else { + k = 0; + } + + /* x is now in primary range */ + t = x * x; + c = x - t*(P1 + t*(P2 + t*(P3 + t*(P4 + t*P5)))); + if (k == 0) + return one - ((x*c)/(c - 2.0) -x); + else + y = one - ((lo - (x*c)/(2.0 - c)) - hi); + + if(k >= -1021) { + y = __HI(y, __HI(y) + (k << 20)); /* add k to y's exponent */ + return y; + } else { + y = __HI(y, __HI(y) + ((k + 1000) << 20)); /* add k to y's exponent */ + return y * twom1000; + } + } + } } --- old/src/java.base/share/classes/java/lang/StrictMath.java 2016-12-15 12:13:38.591083169 -0800 +++ new/src/java.base/share/classes/java/lang/StrictMath.java 2016-12-15 12:13:38.267083154 -0800 @@ -227,7 +227,9 @@ * @return the value e{@code a}, * where e is the base of the natural logarithms. */ - public static native double exp(double a); + public static double exp(double a) { + return FdLibm.Exp.compute(a); + } /** * Returns the natural logarithm (base e) of a {@code double} --- old/src/java.base/share/native/libjava/StrictMath.c 2016-12-15 12:13:39.399083208 -0800 +++ new/src/java.base/share/native/libjava/StrictMath.c 2016-12-15 12:13:39.079083193 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -65,12 +65,6 @@ } JNIEXPORT jdouble JNICALL -Java_java_lang_StrictMath_exp(JNIEnv *env, jclass unused, jdouble d) -{ - return (jdouble) jexp((double)d); -} - -JNIEXPORT jdouble JNICALL Java_java_lang_StrictMath_log(JNIEnv *env, jclass unused, jdouble d) { return (jdouble) jlog((double)d); --- old/test/java/lang/StrictMath/FdlibmTranslit.java 2016-12-15 12:13:40.195083246 -0800 +++ new/test/java/lang/StrictMath/FdlibmTranslit.java 2016-12-15 12:13:39.843083229 -0800 @@ -65,7 +65,8 @@ */ private static double __HI(double x, int high) { long transX = Double.doubleToRawLongBits(x); - return Double.longBitsToDouble((transX & 0x0000_0000_FFFF_FFFFL)|( ((long)high)) << 32 ); + return Double.longBitsToDouble((transX & 0x0000_0000_FFFF_FFFFL) | + ( ((long)high)) << 32 ); } public static double hypot(double x, double y) { @@ -250,4 +251,136 @@ return w; } } + + /** + * Returns the exponential of x. + * + * Method + * 1. Argument reduction: + * Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658. + * Given x, find r and integer k such that + * + * x = k*ln2 + r, |r| <= 0.5*ln2. + * + * Here r will be represented as r = hi-lo for better + * accuracy. + * + * 2. Approximation of exp(r) by a special rational function on + * the interval [0,0.34658]: + * Write + * R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ... + * We use a special Reme algorithm on [0,0.34658] to generate + * a polynomial of degree 5 to approximate R. The maximum error + * of this polynomial approximation is bounded by 2**-59. In + * other words, + * R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5 + * (where z=r*r, and the values of P1 to P5 are listed below) + * and + * | 5 | -59 + * | 2.0+P1*z+...+P5*z - R(z) | <= 2 + * | | + * The computation of exp(r) thus becomes + * 2*r + * exp(r) = 1 + ------- + * R - r + * r*R1(r) + * = 1 + r + ----------- (for better accuracy) + * 2 - R1(r) + * where + * 2 4 10 + * R1(r) = r - (P1*r + P2*r + ... + P5*r ). + * + * 3. Scale back to obtain exp(x): + * From step 1, we have + * exp(x) = 2^k * exp(r) + * + * Special cases: + * exp(INF) is INF, exp(NaN) is NaN; + * exp(-INF) is 0, and + * for finite argument, only exp(0)=1 is exact. + * + * Accuracy: + * according to an error analysis, the error is always less than + * 1 ulp (unit in the last place). + * + * Misc. info. + * For IEEE double + * if x > 7.09782712893383973096e+02 then exp(x) overflow + * if x < -7.45133219101941108420e+02 then exp(x) underflow + * + * Constants: + * The hexadecimal values are the intended ones for the following + * constants. The decimal values may be used, provided that the + * compiler will convert from decimal to binary accurately enough + * to produce the hexadecimal values shown. + */ + static class Exp { + private static final double one = 1.0; + private static final double[] halF = {0.5,-0.5,}; + private static final double huge = 1.0e+300; + private static final double twom1000= 9.33263618503218878990e-302; /* 2**-1000=0x01700000,0*/ + private static final double o_threshold= 7.09782712893383973096e+02; /* 0x40862E42, 0xFEFA39EF */ + private static final double u_threshold= -7.45133219101941108420e+02; /* 0xc0874910, 0xD52D3051 */ + private static final double[] ln2HI ={ 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */ + -6.93147180369123816490e-01}; /* 0xbfe62e42, 0xfee00000 */ + private static final double[] ln2LO ={ 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */ + -1.90821492927058770002e-10,}; /* 0xbdea39ef, 0x35793c76 */ + private static final double invln2 = 1.44269504088896338700e+00; /* 0x3ff71547, 0x652b82fe */ + private static final double P1 = 1.66666666666666019037e-01; /* 0x3FC55555, 0x5555553E */ + private static final double P2 = -2.77777777770155933842e-03; /* 0xBF66C16C, 0x16BEBD93 */ + private static final double P3 = 6.61375632143793436117e-05; /* 0x3F11566A, 0xAF25DE2C */ + private static final double P4 = -1.65339022054652515390e-06; /* 0xBEBBBD41, 0xC5D26BF1 */ + private static final double P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */ + + public static strictfp double compute(double x) { + double y,hi=0,lo=0,c,t; + int k=0,xsb; + /*unsigned*/ int hx; + + hx = __HI(x); /* high word of x */ + xsb = (hx>>31)&1; /* sign bit of x */ + hx &= 0x7fffffff; /* high word of |x| */ + + /* filter out non-finite argument */ + if(hx >= 0x40862E42) { /* if |x|>=709.78... */ + if(hx>=0x7ff00000) { + if(((hx&0xfffff)|__LO(x))!=0) + return x+x; /* NaN */ + else return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */ + } + if(x > o_threshold) return huge*huge; /* overflow */ + if(x < u_threshold) return twom1000*twom1000; /* underflow */ + } + + /* argument reduction */ + if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ + if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ + hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb; + } else { + k = (int)(invln2*x+halF[xsb]); + t = k; + hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */ + lo = t*ln2LO[0]; + } + x = hi - lo; + } + else if(hx < 0x3e300000) { /* when |x|<2**-28 */ + if(huge+x>one) return one+x;/* trigger inexact */ + } + else k = 0; + + /* x is now in primary range */ + t = x*x; + c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); + if(k==0) return one-((x*c)/(c-2.0)-x); + else y = one-((lo-(x*c)/(2.0-c))-hi); + if(k >= -1021) { + y = __HI(y, __HI(y) + (k<<20)); /* add k to y's exponent */ + return y; + } else { + y = __HI(y, __HI(y) + ((k+1000)<<20));/* add k to y's exponent */ + return y*twom1000; + } + } + } } --- /dev/null 2016-12-04 10:29:16.690761514 -0800 +++ new/test/java/lang/StrictMath/ExpTests.java 2016-12-15 12:13:40.647083267 -0800 @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 4123456 + * @key randomness + * @library /lib/testlibrary/ + * @build jdk.testlibrary.RandomFactory + * @build Tests + * @build FdlibmTranslit + * @build ExpTests + * @run main ExpTests + * @summary Tests specifically for StrictMath.exp + */ + +import jdk.testlibrary.RandomFactory; + +/** + * The role of this test is to verify that the FDLIBM exp algorithm is + * being used by running golden file style tests on values that may + * vary from one conforming exponential implementation to another. + */ + +public class ExpTests { + private ExpTests(){} + + public static void main(String [] argv) { + int failures = 0; + + failures += testExp(); + failures += testAgainstTranslit(); + + if (failures > 0) { + System.err.println("Testing the exponential incurred " + + failures + " failures."); + throw new RuntimeException(); + } + } + + static int testExp() { + int failures = 0; + + // From the fdlibm source, the overflow threshold in hex is: + // 0x4086_2E42_FEFA_39EF. + final double OVERFLOW_THRESH = Double.longBitsToDouble(0x4086_2E42_FEFA_39EFL); + + // From the fdlibm source, the underflow threshold in hex is: + // 0xc087_4910_D52D_3051L. + final double UNDERFLOW_THRESH = Double.longBitsToDouble(0xc087_4910_D52D_3051L); + + double [][] testCases = { + // Some of these could be moved to common Math/StrictMath exp testing. + {Double.NaN, Double.NaN}, + {Double.MAX_VALUE, Double.POSITIVE_INFINITY}, + {Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY}, + {Double.NEGATIVE_INFINITY, +0.0}, + {OVERFLOW_THRESH, 0x1.ffff_ffff_fff2ap1023}, + {Math.nextUp(OVERFLOW_THRESH), Double.POSITIVE_INFINITY}, + {Math.nextDown(UNDERFLOW_THRESH), +0.0}, + {UNDERFLOW_THRESH, +Double.MIN_VALUE}, + }; + + for(double[] testCase: testCases) + failures+=testExpCase(testCase[0], testCase[1]); + + return failures; + } + + static int testExpCase(double input, double expected) { + int failures = 0; + + failures+=Tests.test("StrictMath.exp(double)", input, + StrictMath.exp(input), expected); + return failures; + } + + // Initialize shared random number generator + private static java.util.Random random = RandomFactory.getRandom(); + + /** + * Test StrictMath.exp against transliteration port of exp. + */ + private static int testAgainstTranslit() { + int failures = 0; + + double[] decisionPoints = { + // Near overflow threshold + Double.longBitsToDouble(0x4086_2E42_FEFA_39EFL - 512L), + + // Near underflow threshold + Double.longBitsToDouble(0xc087_4910_D52D_3051L - 512L), + + // Straddle algorithm conditional checks + Double.longBitsToDouble(0x4086_2E42_0000_0000L - 512L), + Double.longBitsToDouble(0x3fd6_2e42_0000_0000L - 512L), + Double.longBitsToDouble(0x3FF0_A2B2_0000_0000L - 512L), + Double.longBitsToDouble(0x3e30_0000_0000_0000L - 512L), + + // Other notable points + Double.MIN_NORMAL - Math.ulp(Double.MIN_NORMAL)*512, + -Double.MIN_VALUE*512, + }; + + for (double decisionPoint : decisionPoints) { + double ulp = Math.ulp(decisionPoint); + failures += testRange(decisionPoint - 1024*ulp, ulp, 1_024); + } + + // Try out some random values + for (int i = 0; i < 100; i++) { + double x = Tests.createRandomDouble(random); + failures += testRange(x, Math.ulp(x), 100); + } + + return failures; + } + + private static int testRange(double start, double increment, int count) { + int failures = 0; + double x = start; + for (int i = 0; i < count; i++, x += increment) { + failures += testExpCase(x, FdlibmTranslit.Exp.compute(x)); + } + return failures; + } +} --- old/src/java.base/share/native/libfdlibm/e_exp.c 2016-12-15 12:13:41.715083318 -0800 +++ /dev/null 2016-12-04 10:29:16.690761514 -0800 @@ -1,169 +0,0 @@ -/* - * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* __ieee754_exp(x) - * Returns the exponential of x. - * - * Method - * 1. Argument reduction: - * Reduce x to an r so that |r| <= 0.5*ln2 ~ 0.34658. - * Given x, find r and integer k such that - * - * x = k*ln2 + r, |r| <= 0.5*ln2. - * - * Here r will be represented as r = hi-lo for better - * accuracy. - * - * 2. Approximation of exp(r) by a special rational function on - * the interval [0,0.34658]: - * Write - * R(r**2) = r*(exp(r)+1)/(exp(r)-1) = 2 + r*r/6 - r**4/360 + ... - * We use a special Reme algorithm on [0,0.34658] to generate - * a polynomial of degree 5 to approximate R. The maximum error - * of this polynomial approximation is bounded by 2**-59. In - * other words, - * R(z) ~ 2.0 + P1*z + P2*z**2 + P3*z**3 + P4*z**4 + P5*z**5 - * (where z=r*r, and the values of P1 to P5 are listed below) - * and - * | 5 | -59 - * | 2.0+P1*z+...+P5*z - R(z) | <= 2 - * | | - * The computation of exp(r) thus becomes - * 2*r - * exp(r) = 1 + ------- - * R - r - * r*R1(r) - * = 1 + r + ----------- (for better accuracy) - * 2 - R1(r) - * where - * 2 4 10 - * R1(r) = r - (P1*r + P2*r + ... + P5*r ). - * - * 3. Scale back to obtain exp(x): - * From step 1, we have - * exp(x) = 2^k * exp(r) - * - * Special cases: - * exp(INF) is INF, exp(NaN) is NaN; - * exp(-INF) is 0, and - * for finite argument, only exp(0)=1 is exact. - * - * Accuracy: - * according to an error analysis, the error is always less than - * 1 ulp (unit in the last place). - * - * Misc. info. - * For IEEE double - * if x > 7.09782712893383973096e+02 then exp(x) overflow - * if x < -7.45133219101941108420e+02 then exp(x) underflow - * - * Constants: - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include "fdlibm.h" - -#ifdef __STDC__ -static const double -#else -static double -#endif -one = 1.0, -halF[2] = {0.5,-0.5,}, -huge = 1.0e+300, -twom1000= 9.33263618503218878990e-302, /* 2**-1000=0x01700000,0*/ -o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */ -u_threshold= -7.45133219101941108420e+02, /* 0xc0874910, 0xD52D3051 */ -ln2HI[2] ={ 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */ - -6.93147180369123816490e-01,},/* 0xbfe62e42, 0xfee00000 */ -ln2LO[2] ={ 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */ - -1.90821492927058770002e-10,},/* 0xbdea39ef, 0x35793c76 */ -invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */ -P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ -P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ -P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ -P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ -P5 = 4.13813679705723846039e-08; /* 0x3E663769, 0x72BEA4D0 */ - - -#ifdef __STDC__ - double __ieee754_exp(double x) /* default IEEE double exp */ -#else - double __ieee754_exp(x) /* default IEEE double exp */ - double x; -#endif -{ - double y,hi=0,lo=0,c,t; - int k=0,xsb; - unsigned hx; - - hx = __HI(x); /* high word of x */ - xsb = (hx>>31)&1; /* sign bit of x */ - hx &= 0x7fffffff; /* high word of |x| */ - - /* filter out non-finite argument */ - if(hx >= 0x40862E42) { /* if |x|>=709.78... */ - if(hx>=0x7ff00000) { - if(((hx&0xfffff)|__LO(x))!=0) - return x+x; /* NaN */ - else return (xsb==0)? x:0.0; /* exp(+-inf)={inf,0} */ - } - if(x > o_threshold) return huge*huge; /* overflow */ - if(x < u_threshold) return twom1000*twom1000; /* underflow */ - } - - /* argument reduction */ - if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ - if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ - hi = x-ln2HI[xsb]; lo=ln2LO[xsb]; k = 1-xsb-xsb; - } else { - k = invln2*x+halF[xsb]; - t = k; - hi = x - t*ln2HI[0]; /* t*ln2HI is exact here */ - lo = t*ln2LO[0]; - } - x = hi - lo; - } - else if(hx < 0x3e300000) { /* when |x|<2**-28 */ - if(huge+x>one) return one+x;/* trigger inexact */ - } - else k = 0; - - /* x is now in primary range */ - t = x*x; - c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); - if(k==0) return one-((x*c)/(c-2.0)-x); - else y = one-((lo-(x*c)/(2.0-c))-hi); - if(k >= -1021) { - __HI(y) += (k<<20); /* add k to y's exponent */ - return y; - } else { - __HI(y) += ((k+1000)<<20);/* add k to y's exponent */ - return y*twom1000; - } -} --- old/src/java.base/share/native/libfdlibm/w_exp.c 2016-12-15 12:13:42.275083345 -0800 +++ /dev/null 2016-12-04 10:29:16.690761514 -0800 @@ -1,62 +0,0 @@ - -/* - * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * wrapper exp(x) - */ - -#include "fdlibm.h" - -#ifdef __STDC__ -static const double -#else -static double -#endif -o_threshold= 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */ -u_threshold= -7.45133219101941108420e+02; /* 0xc0874910, 0xD52D3051 */ - -#ifdef __STDC__ - double exp(double x) /* wrapper exp */ -#else - double exp(x) /* wrapper exp */ - double x; -#endif -{ -#ifdef _IEEE_LIBM - return __ieee754_exp(x); -#else - double z; - z = __ieee754_exp(x); - if(_LIB_VERSION == _IEEE_) return z; - if(finite(x)) { - if(x>o_threshold) - return __kernel_standard(x,x,6); /* exp overflow */ - else if(x