in C99
The error function
erfl() for extended double precision



\mathrm{erf}(x) = \frac{1}{\sqrt{\pi}} \int_{-x}^x  {e^\displaystyle{-t^2}} dt

Mar. 12, 2023
Takayuki HOSODA
Japanese Japanese edition is here.

Rational Chebyshev Approximations for the Error Function

list.1 [ erfl.c ]
Formulas used

\operatorname{erf}(x) \ \simeq \ \left\{ \begin{array}{ll}
x \ \mathrm{R}_{77}(x^2) \quad & \text{ for \quad$ |x| \ \le \ 0.605$}\\
c + \ \mathrm{P}_{88}(x) \quad & \text{ for \quad$ 0.605 < \ |x| \ \le \ 1.0$}\\
1 - e^{-\displaystyle{x^2}}\mathrm{R}_{88}(x^2) \quad & \text{ for \quad $1.0 \ < \ x \ \le 3.725$}\\
1 - \displaystyle\frac{e^{-\displaystyle{x^2}}}{x}\ \left(\displaystyle{\frac{1}{\sqrt{\pi}} +  \frac{1}{x^2} \mathrm{R}_{55}
(x^{-1})} }\right) & \text{ for \quad $3.725 \ < \ x$}$}\end{array}
where

  Rpq(z) and Ppq(z) are rational polynomials of degree p in the numerator and q in the denominator.
c is the offset constant at the expansion point.
 Download erfl-0.81.tar.gz — source code archive

Error function approximations and its errors

Calculating the approximation of the error function with extended double precision using the coefficients of the rational Chebyshev approximation as described in Cody's paper [1] the relative error could reach four times the machine epsilon in the range 0.5 ≤ |x| ≤ 0.66 (see figure below). Using the Padé approximation of order 7 : 7 around x = 0 and order 8 : 8 around |x| = 0.8, the relative error was within a machine epsilon in the ranges of |x| ≤ 0.7 and 0.57 ≤ |x| ≤ 1.05, respectively.

Calculation results and errors

The relative error in the calculation of the extended double-precision error function using the appropriate approximation formula for each of the four ranges of x was within a machine epsilon over the entire range.

APPENDIX

The error function can be used to calculate the normalized integral of the standard distribution.


Cumulative distribution of the standard normal distribution and error function calculator
x =    cdf (-x, x) ≃ 
erf (x) ≃ 
 Download erf-0.35.js — source code
REFERENCE
  1. Cody, W. J. "Rational Chebyshev Approximations for the Error Function." Mathematics of Computation, vol. 23, no. 107, 1969, pp. 631-637.
  2. erf(x) — WolframAlpha
  3. Error function — Wikipedia
  4. Multiply-accumulate operation — Wikipedia

www.finetune.co.jp [Mail] © 2000 Takayuki HOSODA.