Sync libm with upstream.

Change-Id: I8ac8ee52122ee19a2e423c3211092023cb4896eb
diff --git a/libm/upstream-freebsd/lib/msun/src/e_cosh.c b/libm/upstream-freebsd/lib/msun/src/e_cosh.c
index a363695..246b5fb 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_cosh.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_cosh.c
@@ -35,6 +35,8 @@
  *	only cosh(0)=1 is exact for finite x.
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
@@ -77,3 +79,7 @@
     /* |x| > overflowthresold, cosh(x) overflow */
 	return huge*huge;
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(cosh, coshl);
+#endif
diff --git a/libm/upstream-freebsd/lib/msun/src/e_lgamma_r.c b/libm/upstream-freebsd/lib/msun/src/e_lgamma_r.c
index 1cff592..7a95ea4 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_lgamma_r.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_lgamma_r.c
@@ -86,8 +86,10 @@
 #include "math.h"
 #include "math_private.h"
 
+static const volatile double vzero = 0;
+
 static const double
-two52=  4.50359962737049600000e+15, /* 0x43300000, 0x00000000 */
+zero=  0.00000000000000000000e+00,
 half=  5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
 one =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
 pi  =  3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */
@@ -154,39 +156,35 @@
 w5  =  8.36339918996282139126e-04, /* 0x3F4B67BA, 0x4CDAD5D1 */
 w6  = -1.63092934096575273989e-03; /* 0xBF5AB89D, 0x0B9E43E4 */
 
-static const double zero=  0.00000000000000000000e+00;
-
-	static double sin_pi(double x)
+/*
+ * Compute sin(pi*x) without actually doing the pi*x multiplication.
+ * sin_pi(x) is only called for x < 0 and |x| < 2**(p-1) where p is
+ * the precision of x.
+ */
+static double
+sin_pi(double x)
 {
+	volatile double vz;
 	double y,z;
-	int n,ix;
+	int n;
 
-	GET_HIGH_WORD(ix,x);
-	ix &= 0x7fffffff;
+	y = -x;
 
-	if(ix<0x3fd00000) return __kernel_sin(pi*x,zero,0);
-	y = -x;		/* x is assume negative */
+	vz = y+0x1p52;			/* depend on 0 <= y < 0x1p52 */
+	z = vz-0x1p52;			/* rint(y) for the above range */
+	if (z == y)
+	    return zero;
 
-    /*
-     * argument reduction, make sure inexact flag not raised if input
-     * is an integer
-     */
-	z = floor(y);
-	if(z!=y) {				/* inexact anyway */
-	    y  *= 0.5;
-	    y   = 2.0*(y - floor(y));		/* y = |x| mod 2.0 */
-	    n   = (int) (y*4.0);
-	} else {
-            if(ix>=0x43400000) {
-                y = zero; n = 0;                 /* y must be even */
-            } else {
-                if(ix<0x43300000) z = y+two52;	/* exact */
-		GET_LOW_WORD(n,z);
-		n &= 1;
-                y  = n;
-                n<<= 2;
-            }
-        }
+	vz = y+0x1p50;
+	GET_LOW_WORD(n,vz);		/* bits for rounded y (units 0.25) */
+	z = vz-0x1p50;			/* y rounded to a multiple of 0.25 */
+	if (z > y) {
+	    z -= 0.25;			/* adjust to round down */
+	    n--;
+	}
+	n &= 7;				/* octant of y mod 2 */
+	y = y - z + n * 0.25;		/* y mod 2 */
+
 	switch (n) {
 	    case 0:   y =  __kernel_sin(pi*y,zero,0); break;
 	    case 1:   
@@ -206,7 +204,7 @@
 {
 	double t,y,z,nadj,p,p1,p2,p3,q,r,w;
 	int32_t hx;
-	int i,lx,ix;
+	int i,ix,lx;
 
 	EXTRACT_WORDS(hx,lx,x);
 
@@ -214,7 +212,7 @@
 	*signgamp = 1;
 	ix = hx&0x7fffffff;
 	if(ix>=0x7ff00000) return x*x;
-	if((ix|lx)==0) return one/zero;
+	if((ix|lx)==0) return one/vzero;
 	if(ix<0x3b900000) {	/* |x|<2**-70, return -log(|x|) */
 	    if(hx<0) {
 	        *signgamp = -1;
@@ -223,9 +221,9 @@
 	}
 	if(hx<0) {
 	    if(ix>=0x43300000) 	/* |x|>=2**52, must be -integer */
-		return one/zero;
+		return one/vzero;
 	    t = sin_pi(x);
-	    if(t==zero) return one/zero; /* -integer */
+	    if(t==zero) return one/vzero; /* -integer */
 	    nadj = __ieee754_log(pi/fabs(t*x));
 	    if(t<zero) *signgamp = -1;
 	    x = -x;
diff --git a/libm/upstream-freebsd/lib/msun/src/e_lgammaf_r.c b/libm/upstream-freebsd/lib/msun/src/e_lgammaf_r.c
index e2d90ef..9a7ab39 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_lgammaf_r.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_lgammaf_r.c
@@ -19,8 +19,10 @@
 #include "math.h"
 #include "math_private.h"
 
+static const volatile float vzero = 0;
+
 static const float
-two23=  8.3886080000e+06, /* 0x4b000000 */
+zero=  0.0000000000e+00,
 half=  5.0000000000e-01, /* 0x3f000000 */
 one =  1.0000000000e+00, /* 0x3f800000 */
 pi  =  3.1415927410e+00, /* 0x40490fdb */
@@ -87,39 +89,30 @@
 w5  =  8.3633989561e-04, /* 0x3a5b3dd2 */
 w6  = -1.6309292987e-03; /* 0xbad5c4e8 */
 
-static const float zero=  0.0000000000e+00;
-
-	static float sin_pif(float x)
+static float
+sin_pif(float x)
 {
+	volatile float vz;
 	float y,z;
-	int n,ix;
+	int n;
 
-	GET_FLOAT_WORD(ix,x);
-	ix &= 0x7fffffff;
+	y = -x;
 
-	if(ix<0x3e800000) return __kernel_sindf(pi*x);
-	y = -x;		/* x is assume negative */
+	vz = y+0x1p23F;			/* depend on 0 <= y < 0x1p23 */
+	z = vz-0x1p23F;			/* rintf(y) for the above range */
+	if (z == y)
+	    return zero;
 
-    /*
-     * argument reduction, make sure inexact flag not raised if input
-     * is an integer
-     */
-	z = floorf(y);
-	if(z!=y) {				/* inexact anyway */
-	    y  *= (float)0.5;
-	    y   = (float)2.0*(y - floorf(y));	/* y = |x| mod 2.0 */
-	    n   = (int) (y*(float)4.0);
-	} else {
-            if(ix>=0x4b800000) {
-                y = zero; n = 0;                 /* y must be even */
-            } else {
-                if(ix<0x4b000000) z = y+two23;	/* exact */
-		GET_FLOAT_WORD(n,z);
-		n &= 1;
-                y  = n;
-                n<<= 2;
-            }
-        }
+	vz = y+0x1p21F;
+	GET_FLOAT_WORD(n,vz);		/* bits for rounded y (units 0.25) */
+	z = vz-0x1p21F;			/* y rounded to a multiple of 0.25 */
+	if (z > y) {
+	    z -= 0.25F;			/* adjust to round down */
+	    n--;
+	}
+	n &= 7;				/* octant of y mod 2 */
+	y = y - z + n * 0.25F;		/* y mod 2 */
+
 	switch (n) {
 	    case 0:   y =  __kernel_sindf(pi*y); break;
 	    case 1:
@@ -147,7 +140,7 @@
 	*signgamp = 1;
 	ix = hx&0x7fffffff;
 	if(ix>=0x7f800000) return x*x;
-	if(ix==0) return one/zero;
+	if(ix==0) return one/vzero;
 	if(ix<0x35000000) {	/* |x|<2**-21, return -log(|x|) */
 	    if(hx<0) {
 	        *signgamp = -1;
@@ -156,9 +149,9 @@
 	}
 	if(hx<0) {
 	    if(ix>=0x4b000000) 	/* |x|>=2**23, must be -integer */
-		return one/zero;
+		return one/vzero;
 	    t = sin_pif(x);
-	    if(t==zero) return one/zero; /* -integer */
+	    if(t==zero) return one/vzero; /* -integer */
 	    nadj = __ieee754_logf(pi/fabsf(t*x));
 	    if(t<zero) *signgamp = -1;
 	    x = -x;
diff --git a/libm/upstream-freebsd/lib/msun/src/e_pow.c b/libm/upstream-freebsd/lib/msun/src/e_pow.c
index 7607a4a..d54af9d 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_pow.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_pow.c
@@ -19,20 +19,20 @@
  *	1. Compute and return log2(x) in two pieces:
  *		log2(x) = w1 + w2,
  *	   where w1 has 53-24 = 29 bit trailing zeros.
- *	2. Perform y*log2(x) = n+y' by simulating muti-precision 
+ *	2. Perform y*log2(x) = n+y' by simulating multi-precision 
  *	   arithmetic, where |y'|<=0.5.
  *	3. Return x**y = 2**n*exp(y'*log2)
  *
  * Special cases:
  *	1.  (anything) ** 0  is 1
  *	2.  (anything) ** 1  is itself
- *	3.  (anything) ** NAN is NAN
+ *	3.  (anything) ** NAN is NAN except 1 ** NAN = 1
  *	4.  NAN ** (anything except 0) is NAN
  *	5.  +-(|x| > 1) **  +INF is +INF
  *	6.  +-(|x| > 1) **  -INF is +0
  *	7.  +-(|x| < 1) **  +INF is +0
  *	8.  +-(|x| < 1) **  -INF is +INF
- *	9.  +-1         ** +-INF is NAN
+ *	9.  +-1         ** +-INF is 1
  *	10. +0 ** (+anything except 0, NAN)               is +0
  *	11. -0 ** (+anything except 0, NAN, odd integer)  is +0
  *	12. +0 ** (-anything except 0, NAN)               is +INF
@@ -141,7 +141,7 @@
 	if(ly==0) { 	
 	    if (iy==0x7ff00000) {	/* y is +-inf */
 	        if(((ix-0x3ff00000)|lx)==0)
-		    return  one;	/* (-1)**+-inf is NaN */
+		    return  one;	/* (-1)**+-inf is 1 */
 	        else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */
 		    return (hy>=0)? y: zero;
 	        else			/* (|x|<1)**-,+inf = inf,0 */
diff --git a/libm/upstream-freebsd/lib/msun/src/e_sinh.c b/libm/upstream-freebsd/lib/msun/src/e_sinh.c
index 17442d0..6c01f4a 100644
--- a/libm/upstream-freebsd/lib/msun/src/e_sinh.c
+++ b/libm/upstream-freebsd/lib/msun/src/e_sinh.c
@@ -32,6 +32,8 @@
  *	only sinh(0)=0 is exact for finite x.
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
@@ -71,3 +73,7 @@
     /* |x| > overflowthresold, sinh(x) overflow */
 	return x*shuge;
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(sinh, sinhl);
+#endif
diff --git a/libm/upstream-freebsd/lib/msun/src/imprecise.c b/libm/upstream-freebsd/lib/msun/src/imprecise.c
index a7503bf..e0ad103 100644
--- a/libm/upstream-freebsd/lib/msun/src/imprecise.c
+++ b/libm/upstream-freebsd/lib/msun/src/imprecise.c
@@ -61,8 +61,6 @@
 	DECLARE_WEAK(f ## l)
 
 DECLARE_IMPRECISE(cosh);
-DECLARE_IMPRECISE(erfc);
-DECLARE_IMPRECISE(erf);
 DECLARE_IMPRECISE(lgamma);
 DECLARE_IMPRECISE(sinh);
 DECLARE_IMPRECISE(tanh);
diff --git a/libm/upstream-freebsd/lib/msun/src/s_erf.c b/libm/upstream-freebsd/lib/msun/src/s_erf.c
index 0886e5e..e1d63bc 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_erf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_erf.c
@@ -111,18 +111,25 @@
 #include "math.h"
 #include "math_private.h"
 
+/* XXX Prevent compilers from erroneously constant folding: */
+static const volatile double tiny= 1e-300;
+
 static const double
-tiny	    = 1e-300,
-half=  5.00000000000000000000e-01, /* 0x3FE00000, 0x00000000 */
-one =  1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */
-two =  2.00000000000000000000e+00, /* 0x40000000, 0x00000000 */
-	/* c = (float)0.84506291151 */
+half= 0.5,
+one = 1,
+two = 2,
+/* c = (float)0.84506291151 */
 erx =  8.45062911510467529297e-01, /* 0x3FEB0AC1, 0x60000000 */
 /*
- * Coefficients for approximation to  erf on [0,0.84375]
+ * In the domain [0, 2**-28], only the first term in the power series
+ * expansion of erf(x) is used.  The magnitude of the first neglected
+ * terms is less than 2**-84.
  */
 efx =  1.28379167095512586316e-01, /* 0x3FC06EBA, 0x8214DB69 */
 efx8=  1.02703333676410069053e+00, /* 0x3FF06EBA, 0x8214DB69 */
+/*
+ * Coefficients for approximation to erf on [0,0.84375]
+ */
 pp0  =  1.28379167095512558561e-01, /* 0x3FC06EBA, 0x8214DB68 */
 pp1  = -3.25042107247001499370e-01, /* 0xBFD4CD7D, 0x691CB913 */
 pp2  = -2.84817495755985104766e-02, /* 0xBF9D2A51, 0xDBD7194F */
@@ -134,7 +141,7 @@
 qq4  =  1.32494738004321644526e-04, /* 0x3F215DC9, 0x221C1A10 */
 qq5  = -3.96022827877536812320e-06, /* 0xBED09C43, 0x42A26120 */
 /*
- * Coefficients for approximation to  erf  in [0.84375,1.25]
+ * Coefficients for approximation to erf in [0.84375,1.25]
  */
 pa0  = -2.36211856075265944077e-03, /* 0xBF6359B8, 0xBEF77538 */
 pa1  =  4.14856118683748331666e-01, /* 0x3FDA8D00, 0xAD92B34D */
@@ -150,7 +157,7 @@
 qa5  =  1.36370839120290507362e-02, /* 0x3F8BEDC2, 0x6B51DD1C */
 qa6  =  1.19844998467991074170e-02, /* 0x3F888B54, 0x5735151D */
 /*
- * Coefficients for approximation to  erfc in [1.25,1/0.35]
+ * Coefficients for approximation to erfc in [1.25,1/0.35]
  */
 ra0  = -9.86494403484714822705e-03, /* 0xBF843412, 0x600D6435 */
 ra1  = -6.93858572707181764372e-01, /* 0xBFE63416, 0xE4BA7360 */
@@ -169,7 +176,7 @@
 sa7  =  6.57024977031928170135e+00, /* 0x401A47EF, 0x8E484A93 */
 sa8  = -6.04244152148580987438e-02, /* 0xBFAEEFF2, 0xEE749A62 */
 /*
- * Coefficients for approximation to  erfc in [1/.35,28]
+ * Coefficients for approximation to erfc in [1/.35,28]
  */
 rb0  = -9.86494292470009928597e-03, /* 0xBF843412, 0x39E86F4A */
 rb1  = -7.99283237680523006574e-01, /* 0xBFE993BA, 0x70C285DE */
@@ -201,7 +208,7 @@
 	if(ix < 0x3feb0000) {		/* |x|<0.84375 */
 	    if(ix < 0x3e300000) { 	/* |x|<2**-28 */
 	        if (ix < 0x00800000)
-		    return 0.125*(8.0*x+efx8*x);  /*avoid underflow */
+		    return (8*x+efx8*x)/8;	/* avoid spurious underflow */
 		return x + efx*x;
 	    }
 	    z = x*x;
@@ -222,15 +229,12 @@
 	x = fabs(x);
  	s = one/(x*x);
 	if(ix< 0x4006DB6E) {	/* |x| < 1/0.35 */
-	    R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
-				ra5+s*(ra6+s*ra7))))));
-	    S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
-				sa5+s*(sa6+s*(sa7+s*sa8)))))));
+	    R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(ra5+s*(ra6+s*ra7))))));
+	    S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(sa5+s*(sa6+s*(sa7+
+		s*sa8)))))));
 	} else {	/* |x| >= 1/0.35 */
-	    R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
-				rb5+s*rb6)))));
-	    S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
-				sb5+s*(sb6+s*sb7))))));
+	    R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(rb5+s*rb6)))));
+	    S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(sb5+s*(sb6+s*sb7))))));
 	}
 	z  = x;
 	SET_LOW_WORD(z,0);
@@ -238,6 +242,10 @@
 	if(hx>=0) return one-r/x; else return  r/x-one;
 }
 
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(erf, erfl);
+#endif
+
 double
 erfc(double x)
 {
@@ -279,23 +287,23 @@
 	    x = fabs(x);
  	    s = one/(x*x);
 	    if(ix< 0x4006DB6D) {	/* |x| < 1/.35 ~ 2.857143*/
-	        R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(
-				ra5+s*(ra6+s*ra7))))));
-	        S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(
-				sa5+s*(sa6+s*(sa7+s*sa8)))))));
+		R=ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*(ra5+s*(ra6+s*ra7))))));
+		S=one+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*(sa5+s*(sa6+s*(sa7+
+		    s*sa8)))))));
 	    } else {			/* |x| >= 1/.35 ~ 2.857143 */
 		if(hx<0&&ix>=0x40180000) return two-tiny;/* x < -6 */
-	        R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(
-				rb5+s*rb6)))));
-	        S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
-				sb5+s*(sb6+s*sb7))))));
+		R=rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*(rb5+s*rb6)))));
+		S=one+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(sb5+s*(sb6+s*sb7))))));
 	    }
 	    z  = x;
 	    SET_LOW_WORD(z,0);
-	    r  =  __ieee754_exp(-z*z-0.5625)*
-			__ieee754_exp((z-x)*(z+x)+R/S);
+	    r  =  __ieee754_exp(-z*z-0.5625)*__ieee754_exp((z-x)*(z+x)+R/S);
 	    if(hx>0) return r/x; else return two-r/x;
 	} else {
 	    if(hx>0) return tiny*tiny; else return two-tiny;
 	}
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(erfc, erfcl);
+#endif
diff --git a/libm/upstream-freebsd/lib/msun/src/s_erff.c b/libm/upstream-freebsd/lib/msun/src/s_erff.c
index a3579f1..d6cfbd2 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_erff.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_erff.c
@@ -19,64 +19,63 @@
 #include "math.h"
 #include "math_private.h"
 
+/* XXX Prevent compilers from erroneously constant folding: */
+static const volatile float tiny = 1e-30;
+
 static const float
-tiny	    = 1e-30,
-half=  5.0000000000e-01, /* 0x3F000000 */
-one =  1.0000000000e+00, /* 0x3F800000 */
-two =  2.0000000000e+00, /* 0x40000000 */
+half= 0.5,
+one = 1,
+two = 2,
+erx = 8.42697144e-01,			/* 0x3f57bb00 */
 /*
- * Coefficients for approximation to  erf on [0,0.84375]
+ * In the domain [0, 2**-14], only the first term in the power series
+ * expansion of erf(x) is used.  The magnitude of the first neglected
+ * terms is less than 2**-42.
  */
-efx =  1.2837916613e-01, /* 0x3e0375d4 */
-efx8=  1.0270333290e+00, /* 0x3f8375d4 */
+efx = 1.28379166e-01, /* 0x3e0375d4 */
+efx8= 1.02703333e+00, /* 0x3f8375d4 */
 /*
- *  Domain [0, 0.84375], range ~[-5.4446e-10,5.5197e-10]:
- *  |(erf(x) - x)/x - p(x)/q(x)| < 2**-31.
+ * Domain [0, 0.84375], range ~[-5.4419e-10, 5.5179e-10]:
+ * |(erf(x) - x)/x - pp(x)/qq(x)| < 2**-31
  */
-pp0  =  1.28379166e-01F, /*  0x1.06eba8p-3 */
-pp1  = -3.36030394e-01F, /* -0x1.58185ap-2 */
-pp2  = -1.86260219e-03F, /* -0x1.e8451ep-10 */
-qq1  =  3.12324286e-01F, /*  0x1.3fd1f0p-2 */
-qq2  =  2.16070302e-02F, /*  0x1.620274p-6 */
-qq3  = -1.98859419e-03F, /* -0x1.04a626p-9 */
+pp0  =  1.28379166e-01, /* 0x3e0375d4 */
+pp1  = -3.36030394e-01, /* 0xbeac0c2d */
+pp2  = -1.86261395e-03, /* 0xbaf422f4 */
+qq1  =  3.12324315e-01, /* 0x3e9fe8f9 */
+qq2  =  2.16070414e-02, /* 0x3cb10140 */
+qq3  = -1.98859372e-03, /* 0xbb025311 */
 /*
- * Domain [0.84375, 1.25], range ~[-1.953e-11,1.940e-11]:
- * |(erf(x) - erx) - p(x)/q(x)| < 2**-36.
+ * Domain [0.84375, 1.25], range ~[-1.023e-9, 1.023e-9]:
+ * |(erf(x) - erx) - pa(x)/qa(x)| < 2**-31
  */
-erx  =  8.42697144e-01F, /*  0x1.af7600p-1.  erf(1) rounded to 16 bits. */
-pa0  =  3.64939137e-06F, /*  0x1.e9d022p-19 */
-pa1  =  4.15109694e-01F, /*  0x1.a91284p-2 */
-pa2  = -1.65179938e-01F, /* -0x1.5249dcp-3 */
-pa3  =  1.10914491e-01F, /*  0x1.c64e46p-4 */
-qa1  =  6.02074385e-01F, /*  0x1.344318p-1 */
-qa2  =  5.35934687e-01F, /*  0x1.126608p-1 */
-qa3  =  1.68576106e-01F, /*  0x1.593e6ep-3 */
-qa4  =  5.62181212e-02F, /*  0x1.cc89f2p-5 */
+pa0  =  3.65041046e-06, /* 0x3674f993 */
+pa1  =  4.15109307e-01, /* 0x3ed48935 */
+pa2  = -2.09395722e-01, /* 0xbe566bd5 */
+pa3  =  8.67677554e-02, /* 0x3db1b34b */
+qa1  =  4.95560974e-01, /* 0x3efdba2b */
+qa2  =  3.71248513e-01, /* 0x3ebe1449 */
+qa3  =  3.92478965e-02, /* 0x3d20c267 */
 /*
- * Domain [1.25,1/0.35], range ~[-7.043e-10,7.457e-10]:
- * |log(x*erfc(x)) + x**2 + 0.5625 - r(x)/s(x)| < 2**-30
+ * Domain [1.25,1/0.35], range ~[-4.821e-9, 4.927e-9]:
+ * |log(x*erfc(x)) + x**2 + 0.5625 - ra(x)/sa(x)| < 2**-28
  */
-ra0  = -9.87132732e-03F, /* -0x1.4376b2p-7 */
-ra1  = -5.53605914e-01F, /* -0x1.1b723cp-1 */
-ra2  = -2.17589188e+00F, /* -0x1.1683a0p+1 */
-ra3  = -1.43268085e+00F, /* -0x1.6ec42cp+0 */
-sa1  =  5.45995426e+00F, /*  0x1.5d6fe4p+2 */
-sa2  =  6.69798088e+00F, /*  0x1.acabb8p+2 */
-sa3  =  1.43113089e+00F, /*  0x1.6e5e98p+0 */
-sa4  = -5.77397496e-02F, /* -0x1.d90108p-5 */
+ra0  = -9.88156721e-03, /* 0xbc21e64c */
+ra1  = -5.43658376e-01, /* 0xbf0b2d32 */
+ra2  = -1.66828310e+00, /* 0xbfd58a4d */
+ra3  = -6.91554189e-01, /* 0xbf3109b2 */
+sa1  =  4.48581553e+00, /* 0x408f8bcd */
+sa2  =  4.10799170e+00, /* 0x408374ab */
+sa3  =  5.53855181e-01, /* 0x3f0dc974 */
 /*
- * Domain [1/0.35, 11], range ~[-2.264e-13,2.336e-13]:
- * |log(x*erfc(x)) + x**2 + 0.5625 - r(x)/s(x)| < 2**-42
+ * Domain [2.85715, 11], range ~[-1.484e-9, 1.505e-9]:
+ * |log(x*erfc(x)) + x**2 + 0.5625 - rb(x)/sb(x)| < 2**-30
  */
-rb0  = -9.86494310e-03F, /* -0x1.434124p-7 */
-rb1  = -6.25171244e-01F, /* -0x1.401672p-1 */
-rb2  = -6.16498327e+00F, /* -0x1.8a8f16p+2 */
-rb3  = -1.66696873e+01F, /* -0x1.0ab70ap+4 */
-rb4  = -9.53764343e+00F, /* -0x1.313460p+3 */
-sb1  =  1.26884899e+01F, /*  0x1.96081cp+3 */
-sb2  =  4.51839523e+01F, /*  0x1.6978bcp+5 */
-sb3  =  4.72810211e+01F, /*  0x1.7a3f88p+5 */
-sb4  =  8.93033314e+00F; /*  0x1.1dc54ap+3 */
+rb0  = -9.86496918e-03, /* 0xbc21a0ae */
+rb1  = -5.48049808e-01, /* 0xbf0c4cfe */
+rb2  = -1.84115684e+00, /* 0xbfebab07 */
+sb1  =  4.87132740e+00, /* 0x409be1ea */
+sb2  =  3.04982710e+00, /* 0x4043305e */
+sb3  = -7.61900663e-01; /* 0xbf430bec */
 
 float
 erff(float x)
@@ -85,9 +84,9 @@
 	float R,S,P,Q,s,y,z,r;
 	GET_FLOAT_WORD(hx,x);
 	ix = hx&0x7fffffff;
-	if(ix>=0x7f800000) {		/* erf(nan)=nan */
+	if(ix>=0x7f800000) {		/* erff(nan)=nan */
 	    i = ((u_int32_t)hx>>31)<<1;
-	    return (float)(1-i)+one/x;	/* erf(+-inf)=+-1 */
+	    return (float)(1-i)+one/x;	/* erff(+-inf)=+-1 */
 	}
 
 	if(ix < 0x3f580000) {		/* |x|<0.84375 */
@@ -105,7 +104,7 @@
 	if(ix < 0x3fa00000) {		/* 0.84375 <= |x| < 1.25 */
 	    s = fabsf(x)-one;
 	    P = pa0+s*(pa1+s*(pa2+s*pa3));
-	    Q = one+s*(qa1+s*(qa2+s*(qa3+s*qa4)));
+	    Q = one+s*(qa1+s*(qa2+s*qa3));
 	    if(hx>=0) return erx + P/Q; else return -erx - P/Q;
 	}
 	if (ix >= 0x40800000) {		/* inf>|x|>=4 */
@@ -113,12 +112,12 @@
 	}
 	x = fabsf(x);
  	s = one/(x*x);
-	if(ix< 0x4036DB6E) {	/* |x| < 1/0.35 */
+	if(ix< 0x4036db8c) {	/* |x| < 2.85715 ~ 1/0.35 */
 	    R=ra0+s*(ra1+s*(ra2+s*ra3));
-	    S=one+s*(sa1+s*(sa2+s*(sa3+s*sa4)));
-	} else {	/* |x| >= 1/0.35 */
-	    R=rb0+s*(rb1+s*(rb2+s*(rb3+s*rb4)));
-	    S=one+s*(sb1+s*(sb2+s*(sb3+s*sb4)));
+	    S=one+s*(sa1+s*(sa2+s*sa3));
+	} else {	/* |x| >= 2.85715 ~ 1/0.35 */
+	    R=rb0+s*(rb1+s*rb2);
+	    S=one+s*(sb1+s*(sb2+s*sb3));
 	}
 	SET_FLOAT_WORD(z,hx&0xffffe000);
 	r  = expf(-z*z-0.5625F)*expf((z-x)*(z+x)+R/S);
@@ -132,8 +131,8 @@
 	float R,S,P,Q,s,y,z,r;
 	GET_FLOAT_WORD(hx,x);
 	ix = hx&0x7fffffff;
-	if(ix>=0x7f800000) {			/* erfc(nan)=nan */
-						/* erfc(+-inf)=0,2 */
+	if(ix>=0x7f800000) {			/* erfcf(nan)=nan */
+						/* erfcf(+-inf)=0,2 */
 	    return (float)(((u_int32_t)hx>>31)<<1)+one/x;
 	}
 
@@ -155,7 +154,7 @@
 	if(ix < 0x3fa00000) {		/* 0.84375 <= |x| < 1.25 */
 	    s = fabsf(x)-one;
 	    P = pa0+s*(pa1+s*(pa2+s*pa3));
-	    Q = one+s*(qa1+s*(qa2+s*(qa3+s*qa4)));
+	    Q = one+s*(qa1+s*(qa2+s*qa3));
 	    if(hx>=0) {
 	        z  = one-erx; return z - P/Q;
 	    } else {
@@ -165,13 +164,13 @@
 	if (ix < 0x41300000) {		/* |x|<11 */
 	    x = fabsf(x);
  	    s = one/(x*x);
-	    if(ix< 0x4036DB6D) {	/* |x| < 1/.35 ~ 2.857143*/
-	        R=ra0+s*(ra1+s*(ra2+s*ra3));
-	        S=one+s*(sa1+s*(sa2+s*(sa3+s*sa4)));
-	    } else {			/* |x| >= 1/.35 ~ 2.857143 */
+	    if(ix< 0x4036db8c) {	/* |x| < 2.85715 ~ 1/.35 */
+		R=ra0+s*(ra1+s*(ra2+s*ra3));
+		S=one+s*(sa1+s*(sa2+s*sa3));
+	    } else {			/* |x| >= 2.85715 ~ 1/.35 */
 		if(hx<0&&ix>=0x40a00000) return two-tiny;/* x < -5 */
-	        R=rb0+s*(rb1+s*(rb2+s*(rb3+s*rb4)));
-		S=one+s*(sb1+s*(sb2+s*(sb3+s*sb4)));
+		R=rb0+s*(rb1+s*rb2);
+		S=one+s*(sb1+s*(sb2+s*sb3));
 	    }
 	    SET_FLOAT_WORD(z,hx&0xffffe000);
 	    r  = expf(-z*z-0.5625F)*expf((z-x)*(z+x)+R/S);
diff --git a/libm/upstream-freebsd/lib/msun/src/s_rintl.c b/libm/upstream-freebsd/lib/msun/src/s_rintl.c
index e55b40e..b43df89 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_rintl.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_rintl.c
@@ -29,7 +29,6 @@
 
 #include <float.h>
 #include <math.h>
-#include <stdint.h>
 
 #include "fpmath.h"
 
diff --git a/libm/upstream-freebsd/lib/msun/src/s_tanh.c b/libm/upstream-freebsd/lib/msun/src/s_tanh.c
index 96e3565..6d26c69 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_tanh.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_tanh.c
@@ -37,10 +37,13 @@
  *	only tanh(0)=0 is exact for finite argument.
  */
 
+#include <float.h>
+
 #include "math.h"
 #include "math_private.h"
 
-static const double one = 1.0, two = 2.0, tiny = 1.0e-300, huge = 1.0e300;
+static const volatile double tiny = 1.0e-300;
+static const double one = 1.0, two = 2.0, huge = 1.0e300;
 
 double
 tanh(double x)
@@ -75,3 +78,7 @@
 	}
 	return (jx>=0)? z: -z;
 }
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(tanh, tanhl);
+#endif
diff --git a/libm/upstream-freebsd/lib/msun/src/s_tanhf.c b/libm/upstream-freebsd/lib/msun/src/s_tanhf.c
index 04f09c6..f537be4 100644
--- a/libm/upstream-freebsd/lib/msun/src/s_tanhf.c
+++ b/libm/upstream-freebsd/lib/msun/src/s_tanhf.c
@@ -19,7 +19,9 @@
 #include "math.h"
 #include "math_private.h"
 
-static const float one=1.0, two=2.0, tiny = 1.0e-30, huge = 1.0e30;
+static const volatile float tiny = 1.0e-30;
+static const float one=1.0, two=2.0, huge = 1.0e30;
+
 float
 tanhf(float x)
 {