vnl_erf.h
Go to the documentation of this file.
1 // This is core/vnl/vnl_erf.h
2 #ifndef vnl_erf_h_
3 #define vnl_erf_h_
4 //:
5 // \file
6 // \brief Error Function (erf) approximations
7 // \author Tim Cootes, Ian Scott
8 
9 #include <vnl/vnl_gamma.h>
10 #include <vnl/vnl_math.h>
11 #include "vnl/vnl_export.h"
12 
13 //: The Error function.
14 // erf(x) = (2/sqrt(pi)) Integral from 0 to x (exp(-t^2) dt)
15 // \note the output ranges from -1 to 1, and vnl_erf(0) = 0.
16 inline double vnl_erf(double x)
17 { return (x<0)?-vnl_gamma_p(0.5,x*x):vnl_gamma_p(0.5,x*x); }
18 
19 //: The Complementary Error function.
20 // erfc(x) = 1 - erf(x) = 1 - (2/sqrt(pi)) Integral from 0 to x (exp(-t^2) dt)
21 // This value is useful for large x, when erf(x) ~= 1 and erfc(x) < eps.
22 // \note the output ranges from 0 to 2, and vnl_erfc(0) = 1.
23 VNL_EXPORT double vnl_erfc(double x);
24 
25 //: The Scaled Complementary Error function.
26 // erfc_scaled(x) = exp(x^2) * erfc(x)
27 // This value is useful for very large x, where erf and erfc returns
28 // respectively ~1 and ~0.
29 // It can be approximated by (1/sqrt(pi)) * (1/x)
30 inline double vnl_scaled_erfc(double x)
31 { return (vnl_math::two_over_sqrtpi/2.)*(1./x); }
32 
33 #endif // vnl_erf_h_
double vnl_scaled_erfc(double x)
The Scaled Complementary Error function.
Definition: vnl_erf.h:30
Namespace with standard math functions.
double vnl_erf(double x)
The Error function.
Definition: vnl_erf.h:16
VNL_EXPORT double vnl_erfc(double x)
The Complementary Error function.
Definition: vnl_erf.cxx:13
Complete and incomplete gamma function approximations.
double vnl_gamma_p(double a, double x)
Normalised Incomplete gamma function, P(a,x).
Definition: vnl_gamma.cxx:92