about summary refs log tree commit diff
path: root/src/math/erff.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-03-19 22:07:43 -0400
committerRich Felker <dalias@aerifal.cx>2012-03-19 22:07:43 -0400
commit97721a5508415a2f10eb068e022093811c9ff8be (patch)
tree88e9ce153895ad949576fa7ce1eeee4b02286479 /src/math/erff.c
parentacb744921b73f5a73803e533e5e4a4896d164a26 (diff)
parent0cbb65479147ecdaa664e88cc2a5a925f3de502f (diff)
downloadmusl-97721a5508415a2f10eb068e022093811c9ff8be.tar.gz
musl-97721a5508415a2f10eb068e022093811c9ff8be.tar.xz
musl-97721a5508415a2f10eb068e022093811c9ff8be.zip
Merge remote branch 'nsz/master'
Diffstat (limited to 'src/math/erff.c')
-rw-r--r--src/math/erff.c57
1 files changed, 27 insertions, 30 deletions
diff --git a/src/math/erff.c b/src/math/erff.c
index eef4851e..a0a304e5 100644
--- a/src/math/erff.c
+++ b/src/math/erff.c
@@ -17,9 +17,6 @@
 
 static const float
 tiny = 1e-30,
-half =  5.0000000000e-01, /* 0x3F000000 */
-one  =  1.0000000000e+00, /* 0x3F800000 */
-two  =  2.0000000000e+00, /* 0x40000000 */
 /* c = (subfloat)0.84506291151 */
 erx  =  8.4506291151e-01, /* 0x3f58560b */
 /*
@@ -100,7 +97,7 @@ float erff(float x)
 	if (ix >= 0x7f800000) {
 		/* erf(nan)=nan, erf(+-inf)=+-1 */
 		i = ((uint32_t)hx>>31)<<1;
-		return (float)(1-i)+one/x;
+		return (float)(1-i)+1.0f/x;
 	}
 	if (ix < 0x3f580000) {  /* |x| < 0.84375 */
 		if (ix < 0x31800000) {  /* |x| < 2**-28 */
@@ -111,42 +108,42 @@ float erff(float x)
 		}
 		z = x*x;
 		r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
-		s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
+		s = 1.0f+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
 		y = r/s;
 		return x + x*y;
 	}
 	if (ix < 0x3fa00000) {  /* 0.84375 <= |x| < 1.25 */
-		s = fabsf(x)-one;
+		s = fabsf(x)-1.0f;
 		P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
-		Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
+		Q = 1.0f+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
 		if (hx >= 0)
 			return erx + P/Q;
 		return -erx - P/Q;
 	}
 	if (ix >= 0x40c00000) {  /* inf > |x| >= 6 */
 		if (hx >= 0)
-			return one - tiny;
-		return tiny - one;
+			return 1.0f - tiny;
+		return tiny - 1.0f;
 	}
 	x = fabsf(x);
-	s = one/(x*x);
+	s = 1.0f/(x*x);
 	if (ix < 0x4036DB6E) {   /* |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*(
+		S = 1.0f+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*(
+		S = 1.0f+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
 		     sb5+s*(sb6+s*sb7))))));
 	}
 	GET_FLOAT_WORD(ix, x);
 	SET_FLOAT_WORD(z, ix&0xfffff000);
 	r = expf(-z*z - 0.5625f) * expf((z-x)*(z+x) + R/S);
 	if (hx >= 0)
-		return one - r/x;
-	return  r/x - one;
+		return 1.0f - r/x;
+	return  r/x - 1.0f;
 }
 
 float erfcf(float x)
@@ -158,50 +155,50 @@ float erfcf(float x)
 	ix = hx & 0x7fffffff;
 	if (ix >= 0x7f800000) {
 		/* erfc(nan)=nan, erfc(+-inf)=0,2 */
-		return (float)(((uint32_t)hx>>31)<<1) + one/x;
+		return (float)(((uint32_t)hx>>31)<<1) + 1.0f/x;
 	}
 
 	if (ix < 0x3f580000) {  /* |x| < 0.84375 */
 		if (ix < 0x23800000)  /* |x| < 2**-56 */
-			return one - x;
+			return 1.0f - x;
 		z = x*x;
 		r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4)));
-		s = one+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
+		s = 1.0f+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
 		y = r/s;
 		if (hx < 0x3e800000) {  /* x<1/4 */
-			return one - (x+x*y);
+			return 1.0f - (x+x*y);
 		} else {
 			r = x*y;
-			r += (x-half);
-			return half - r ;
+			r += (x-0.5f);
+			return 0.5f - r ;
 		}
 	}
 	if (ix < 0x3fa00000) {  /* 0.84375 <= |x| < 1.25 */
-		s = fabsf(x)-one;
+		s = fabsf(x)-1.0f;
 		P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6)))));
-		Q = one+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
+		Q = 1.0f+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
 		if(hx >= 0) {
-			z = one - erx;
+			z = 1.0f - erx;
 			return z - P/Q;
 		} else {
 			z = erx + P/Q;
-			return one + z;
+			return 1.0f + z;
 		}
 	}
 	if (ix < 0x41e00000) {  /* |x| < 28 */
 		x = fabsf(x);
-		s = one/(x*x);
+		s = 1.0f/(x*x);
 		if (ix < 0x4036DB6D) {  /* |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*(
+			S = 1.0f+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 >= 0x40c00000) /* x < -6 */
-				return two-tiny;
+				return 2.0f-tiny;
 			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*(
+			S = 1.0f+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
 			     sb5+s*(sb6+s*sb7))))));
 		}
 		GET_FLOAT_WORD(ix, x);
@@ -209,9 +206,9 @@ float erfcf(float x)
 		r = expf(-z*z - 0.5625f) * expf((z-x)*(z+x) + R/S);
 		if (hx > 0)
 			return r/x;
-		return two - r/x;
+		return 2.0f - r/x;
 	}
 	if (hx > 0)
 		return tiny*tiny;
-	return two - tiny;
+	return 2.0f - tiny;
 }