Name
erf
Synopsis
Calculates the error function of a floating-point number
#include <math.h> doubleerf
( doublex
); floaterff
( floatx
); long doubleerfl
( long doublex
);
The function erf()
, called
the error function, is associated with the Gaussian function or
normal distribution. If the measured values of a given random
variable conform to a normal distribution with the standard
deviation σ, then the
probability that a single measurement has an error within ±
a
is erf
( a
/
(σ × √2) ).
The return value of erf(
x
)
is
The function erfc()
is the
complementary error function, defined as erfc(
x
)
= 1 − erf(
x
)
.
Example
/*
* Given a normal distribution with mean 0 and standard deviation 1,
* calculate the probability that the random variable is within the
* range [0, 1.125]
*/
double sigma = 1.0; // The standard deviation
double bound = 1.125;
double probability; // probability that mean <= value <= bound
probability = 0.5 *erf
( bound / (sigma * sqrt(2.0)) );
See Also
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.