What is erfc in C?

The erfc function is defined in the math.h header file in C. It takes in a single parameter: a double value. It then computes the complementary error function of the given argument and returns a type double value.

The complementary error function in mathematics is defined as follows:

erfc zz = 12π1- \frac{2}{\sqrt{\pi}} 0arget2dt\int_{0}^{arg} e^{-t^2} dt

= 2π\frac{2}{\sqrt{\pi}} arget2dt\int_{arg}^{\infty} e^{-t^2} dt

The argument to the erfc function serves as the lower limit in the integral above.

The error function is most often used in probability and statistics. It integrates the normal distribution and gives the probability that a normally distributed random variable Y (with mean 0 and variance ½) falls into the range [−x, x].

The complementary error function, combined with its series expansion, provides approximate expressions for small and large values of x.

The figure below shows the plot of the erfc function:

erfc function [Image taken from WorlframAlpha]
erfc function [Image taken from WorlframAlpha]

The illustration below shows how erfc function works:

How does erfc work?

Declaration

The erfc function is defined as follows:

double erfc(double arg);

It takes in a single value of type double and computes its complementary error function. It then returns the answer of type double.

Error handling

The erfc function returns special values for certain arguments:

Special Value Returned
+INFINITY +0
-INFINITY +2
NAN NAN

Examples

The following code snippet shows how we can use the erfc function:

#include <stdio.h> // Including header file for printf function
#include <math.h> // Including header file for erfc function
int main (){
double param, result;
param = 2.0;
result = erfc(param);
printf("erfc (%f) = %f\n", param, result);
return 0;
}

The following code snippet shows how error handling in erfc function works:

#include <stdio.h> // Including header file for printf function
#include <math.h> // Including header file for erfc function
int main (){
printf("erfc (%f) = %f\n", INFINITY, erfc(INFINITY));
printf("erfc (%f) = %f\n", -INFINITY, erfc(-INFINITY));
return 0;
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved