Skip to content

Commit

Permalink
Fix provided implementation of erf and erfc functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
xxuejie committed Nov 19, 2012
1 parent 1b2257c commit f7dd27a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/math.c
Expand Up @@ -51,7 +51,7 @@ erf(double x)
term *= xsqr/j;
sum += term/(2*j+1);
++j;
} while (fabs(term)/sum > MATH_TOLERANCE);
} while (fabs(term/sum) > MATH_TOLERANCE);
return two_sqrtpi*sum;
}

Expand All @@ -64,7 +64,8 @@ erfc(double x)
double b = x;
double c = x;
double d = x*x+0.5;
double q1, q2;
double q1;
double q2 = b/d;
double n = 1.0;
double t;
if (fabs(x) < 2.2) {
Expand Down
8 changes: 6 additions & 2 deletions test/t/math.rb
Expand Up @@ -110,8 +110,12 @@
check_float(Math.erf(1), 0.842700792949715)
end

assert('Math.erfc 1') do
check_float(Math.erfc(1), 0.157299207050285)
assert('Math.erf -1') do
check_float(Math.erf(-1), -0.8427007929497148)
end

assert('Math.erfc -1') do
check_float(Math.erfc(-1), 1.8427007929497148)
end
end

0 comments on commit f7dd27a

Please sign in to comment.