Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix manual implementations of erf and erfc functions #563

Merged
merged 2 commits into from

2 participants

@xxuejie

The manual implementations of erf and erfc functions provided for MSVC contain bugs. They are taken from earlier threads in the original post:

http://www.digitalmars.com/archives/cplusplus/3634.html

This commits contain fix coming from the last thread of the same post. New test cases are also added to test the behaviour.

@matz matz merged commit 8894cbe into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 11 additions and 2 deletions.
  1. +3 −2 src/math.c
  2. +8 −0 test/t/math.rb
View
5 src/math.c
@@ -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;
}
@@ -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) {
View
8 test/t/math.rb
@@ -113,5 +113,13 @@
assert('Math.erfc 1') do
check_float(Math.erfc(1), 0.157299207050285)
end
+
+ 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
Something went wrong with that request. Please try again.