erfc, erfcf, erfcl

Header: <math.h>

1-3) Computes the complementary error function of arg, that is 1.0 - erf(arg), but without loss of precision for large arg.

# Declarations

float erfcf( float arg );

(since C99)

double erfc( double arg );

(since C99)

long double erfcl( long double arg );

(since C99)

#define erfc( arg )

(since C99)

# Parameters

# Return value

If a range error occurs due to underflow, the correct result (after rounding) is returned.

# Notes

For the IEEE-compatible type double, underflow is guaranteed if arg > 26.55.

# Example

#include <math.h>
#include <stdio.h>
 
double normalCDF(double x) // Phi(-∞, x) aka N(x)
{
    return erfc(-x / sqrt(2)) / 2;
}
 
int main(void)
{
    puts("normal cumulative distribution function:");
    for (double n = 0; n < 1; n += 0.1)
        printf("normalCDF(%.2f) %5.2f%%\n", n, 100 * normalCDF(n));
 
    printf("special values:\n"
           "erfc(-Inf) = %f\n"
           "erfc(Inf) = %f\n",
           erfc(-INFINITY),
           erfc(INFINITY));
}

# See also