Commit 403b2595 authored by Peter Eastman's avatar Peter Eastman
Browse files

In double precision mode, compute erfc() exactly instead of approximating it

parent 0a1f4594
...@@ -6,6 +6,9 @@ if (!isExcluded || needCorrection) { ...@@ -6,6 +6,9 @@ if (!isExcluded || needCorrection) {
const real expAlphaRSqr = EXP(-alphaR*alphaR); const real expAlphaRSqr = EXP(-alphaR*alphaR);
const real prefactor = 138.935456f*posq1.w*posq2.w*invR; const real prefactor = 138.935456f*posq1.w*posq2.w*invR;
#ifdef USE_DOUBLE_PRECISION
const real erfcAlphaR = erfc(alphaR);
#else
// This approximation for erfc is from Abramowitz and Stegun (1964) p. 299. They cite the following as // This approximation for erfc is from Abramowitz and Stegun (1964) p. 299. They cite the following as
// the original source: C. Hastings, Jr., Approximations for Digital Computers (1955). It has a maximum // the original source: C. Hastings, Jr., Approximations for Digital Computers (1955). It has a maximum
// error of 3e-7. // error of 3e-7.
...@@ -15,6 +18,7 @@ if (!isExcluded || needCorrection) { ...@@ -15,6 +18,7 @@ if (!isExcluded || needCorrection) {
t *= t; t *= t;
t *= t; t *= t;
const real erfcAlphaR = RECIP(t*t); const real erfcAlphaR = RECIP(t*t);
#endif
real tempForce = 0.0f; real tempForce = 0.0f;
if (needCorrection) { if (needCorrection) {
// Subtract off the part of this interaction that was included in the reciprocal space contribution. // Subtract off the part of this interaction that was included in the reciprocal space contribution.
......
...@@ -6,6 +6,9 @@ if (!isExcluded || needCorrection) { ...@@ -6,6 +6,9 @@ if (!isExcluded || needCorrection) {
const real expAlphaRSqr = EXP(-alphaR*alphaR); const real expAlphaRSqr = EXP(-alphaR*alphaR);
const real prefactor = 138.935456f*posq1.w*posq2.w*invR; const real prefactor = 138.935456f*posq1.w*posq2.w*invR;
#ifdef USE_DOUBLE_PRECISION
const real erfcAlphaR = erfc(alphaR);
#else
// This approximation for erfc is from Abramowitz and Stegun (1964) p. 299. They cite the following as // This approximation for erfc is from Abramowitz and Stegun (1964) p. 299. They cite the following as
// the original source: C. Hastings, Jr., Approximations for Digital Computers (1955). It has a maximum // the original source: C. Hastings, Jr., Approximations for Digital Computers (1955). It has a maximum
// error of 3e-7. // error of 3e-7.
...@@ -15,6 +18,7 @@ if (!isExcluded || needCorrection) { ...@@ -15,6 +18,7 @@ if (!isExcluded || needCorrection) {
t *= t; t *= t;
t *= t; t *= t;
const real erfcAlphaR = RECIP(t*t); const real erfcAlphaR = RECIP(t*t);
#endif
real tempForce = 0; real tempForce = 0;
if (needCorrection) { if (needCorrection) {
// Subtract off the part of this interaction that was included in the reciprocal space contribution. // Subtract off the part of this interaction that was included in the reciprocal space contribution.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment