diff options
author | nsz <nsz@port70.net> | 2012-03-19 23:41:19 +0100 |
---|---|---|
committer | nsz <nsz@port70.net> | 2012-03-19 23:41:19 +0100 |
commit | 0cbb65479147ecdaa664e88cc2a5a925f3de502f (patch) | |
tree | 7b6dc53fcec6497d55746d3cc47f167a20b7aa57 /src/math/erff.c | |
parent | b03255af77776703c8d48819e824d09f6f54ba86 (diff) | |
download | musl-0cbb65479147ecdaa664e88cc2a5a925f3de502f.tar.gz musl-0cbb65479147ecdaa664e88cc2a5a925f3de502f.tar.bz2 musl-0cbb65479147ecdaa664e88cc2a5a925f3de502f.tar.xz musl-0cbb65479147ecdaa664e88cc2a5a925f3de502f.zip |
code cleanup of named constants
zero, one, two, half are replaced by const literals
The policy was to use the f suffix for float consts (1.0f),
but don't use suffix for long double consts (these consts
can be exactly represented as double).
Diffstat (limited to 'src/math/erff.c')
-rw-r--r-- | src/math/erff.c | 57 |
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; } |