about summary refs log tree commit diff
path: root/src/math/erf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/erf.c')
-rw-r--r--src/math/erf.c57
1 files changed, 27 insertions, 30 deletions
diff --git a/src/math/erf.c b/src/math/erf.c
index 18ee01cf..dd8c3a77 100644
--- a/src/math/erf.c
+++ b/src/math/erf.c
@@ -107,9 +107,6 @@
 
 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 */
 erx  = 8.45062911510467529297e-01, /* 0x3FEB0AC1, 0x60000000 */
 /*
@@ -190,7 +187,7 @@ double erf(double x)
 	if (ix >= 0x7ff00000) {
 		/* erf(nan)=nan, erf(+-inf)=+-1 */
 		i = ((uint32_t)hx>>31)<<1;
-		return (double)(1-i) + one/x;
+		return (double)(1-i) + 1.0/x;
 	}
 	if (ix < 0x3feb0000) {  /* |x|<0.84375 */
 		if (ix < 0x3e300000) {  /* |x|<2**-28 */
@@ -201,42 +198,42 @@ double erf(double 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.0+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
 		y = r/s;
 		return x + x*y;
 	}
 	if (ix < 0x3ff40000) {  /* 0.84375 <= |x| < 1.25 */
-		s = fabs(x)-one;
+		s = fabs(x)-1.0;
 		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.0+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 >= 0x40180000) {  /* inf > |x| >= 6 */
 		if (hx >= 0)
-			return one-tiny;
-		return tiny-one;
+			return 1.0 - tiny;
+		return tiny - 1.0;
 	}
 	x = fabs(x);
-	s = one/(x*x);
+	s = 1.0/(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*(
+		S = 1.0+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.0+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
 		     sb5+s*(sb6+s*sb7))))));
 	}
 	z = x;
 	SET_LOW_WORD(z,0);
 	r = exp(-z*z-0.5625)*exp((z-x)*(z+x)+R/S);
 	if (hx >= 0)
-		return one-r/x;
-	return r/x-one;
+		return 1.0 - r/x;
+	return r/x - 1.0;
 }
 
 double erfc(double x)
@@ -248,49 +245,49 @@ double erfc(double x)
 	ix = hx & 0x7fffffff;
 	if (ix >= 0x7ff00000) {
 		/* erfc(nan)=nan, erfc(+-inf)=0,2 */
-		return (double)(((uint32_t)hx>>31)<<1) + one/x;
+		return (double)(((uint32_t)hx>>31)<<1) + 1.0/x;
 	}
 	if (ix < 0x3feb0000) {  /* |x| < 0.84375 */
 		if (ix < 0x3c700000)  /* |x| < 2**-56 */
-			return one - x;
+			return 1.0 - 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.0+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5))));
 		y = r/s;
 		if (hx < 0x3fd00000) {  /* x < 1/4 */
-			return one - (x+x*y);
+			return 1.0 - (x+x*y);
 		} else {
 			r = x*y;
-			r += x-half;
-			return half - r ;
+			r += x - 0.5;
+			return 0.5 - r ;
 		}
 	}
 	if (ix < 0x3ff40000) {  /* 0.84375 <= |x| < 1.25 */
-		s = fabs(x)-one;
+		s = fabs(x)-1.0;
 		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.0+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6)))));
 		if (hx >= 0) {
-			z = one-erx;
+			z = 1.0-erx;
 			return z - P/Q;
 		} else {
 			z = erx+P/Q;
-			return one+z;
+			return 1.0 + z;
 		}
 	}
 	if (ix < 0x403c0000) {  /* |x| < 28 */
 		x = fabs(x);
-		s = one/(x*x);
+		s = 1.0/(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*(
+			S = 1.0+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)  /* x < -6 */
-				return two-tiny;
+				return 2.0 - 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.0+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*(
 			     sb5+s*(sb6+s*sb7))))));
 		}
 		z = x;
@@ -298,9 +295,9 @@ double erfc(double x)
 		r = exp(-z*z-0.5625)*exp((z-x)*(z+x)+R/S);
 		if (hx > 0)
 			return r/x;
-		return two-r/x;
+		return 2.0 - r/x;
 	}
 	if (hx > 0)
 		return tiny*tiny;
-	return two-tiny;
+	return 2.0 - tiny;
 }