Name

erf

Synopsis

Calculates the error function of a floating-point number

#include <math.h>
doubleerf( double x );
float erff( float x );
long double erfl( long double x );

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

image with no caption

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

erfc()

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.