What is erfcl in C?

The erfcl function is defined in the tgmath.h header file in C. It takes in a single parameter: a long double value. It then computes the complementary error function of the given argument and returns a type long 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 erfcl 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 erfc function in mathematics caters to values of all types. There is a unique function for each data type in C.

The figure below shows the plot of the erfc function:

erfc function [Image taken from WolframAlpha]
erfc function [Image taken from WolframAlpha]

The illustration below shows how erfcl function works:

How does erfcl work?

Declaration

The erfcl function is defined as follows:

long double erfcl(long double arg);

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

Error handling

The erfcl function returns special values for certain arguments:

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

Example

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

#include <stdio.h> // Including header file for printf function
#include <tgmath.h> // Including header file for erfcl function
int main (){
long double param, result;
param = 1.5;
result = erfcl(param);
printf("erfcl (%Lf) = %Lf\n", param, result);
return 0;
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved