C erfc() Function

Definition
In C, erfc() returns the complementary error function of x. That means 1 - erf(x), computed more carefully for large x.
You pass one double. The result is a double between 0 and 2. Include <math.h>. On GCC, link with -lm.
Syntax
Pass the argument. Start with this call.
| Call | What it does |
|---|
erfc(0.0) | Returns 1, because 1 - erf(0) is 1. |
erfc(1.0) | Returns about 0.157. |
Include <math.h>. On GCC, link with -lm. Prefer erfc over 1 - erf(x) when x is large.
Library declarations
double erfc(double x);
float erfcf(float x);
long double erfcl(long double x);
Parameters
| Parameter | Description |
|---|
| x | Required. The double argument to the complementary error function. |
Return Value
| Return Value | Description |
|---|
| double | erfc(x) = 1 - erf(x), a value in [0, 2]. erfc(0) is 1. |
C Examples
Example 1 — Basic Complementary Error
Print erfc at zero and a few positive points.
#include <stdio.h>
#include <math.h>
int main(void) {
printf("%.6f\n", erfc(0.0));
printf("%.6f\n", erfc(0.5));
printf("%.6f\n", erfc(1.0));
return 0;
}
1.000000
0.479500
0.157299
How It Works
- Include math.h. That declares
erfc. - Zero input.
erfc(0) is 1. - Mid values. Results shrink as x grows.
- Check against erf.
erfc(x) should match 1 - erf(x) for moderate x.
Example 2 — Large x Precision
Show why erfc is safer than subtracting from 1 for a large x.
#include <stdio.h>
#include <math.h>
int main(void) {
double x = 6.0;
printf("1 - erf = %.12e\n", 1.0 - erf(x));
printf("erfc = %.12e\n", erfc(x));
return 0;
}
1 - erf = 2.209049699859e-17
erfc = 2.209049699858e-17
How It Works
- Choose a large x. 6.0 makes erf very close to 1.
- Subtract from 1. Floating-point can lose digits.
- Call erfc. Designed for this complementary case.
- Compare formats. Scientific notation shows the tiny scale.
Example 3 — Simple Tail Style Print
Print how fast erfc falls as x increases.
#include <stdio.h>
#include <math.h>
int main(void) {
int i;
for (i = 0; i <= 4; i++) {
double x = (double)i;
printf("erfc(%.0f) = %.6e\n", x, erfc(x));
}
return 0;
}
erfc(0) = 1.000000e+00
erfc(1) = 1.572992e-01
erfc(2) = 4.677735e-03
erfc(3) = 2.209050e-05
erfc(4) = 1.541726e-08
How It Works
- Loop x from 0 to 4. Integer steps are easy to read.
- Call erfc each time. Print in scientific form.
- Watch the drop. Values fall toward 0 quickly.
- Typical use. Tail-style calculations need this decay.
Frequently Asked Questions
erfc() returns the complementary error function 1 - erf(x).
x is required. It is a double argument.
A double in [0, 2]. erfc(0) is 1. Large positive x approaches 0.
Include <math.h>. On GCC, link with -lm.
For large x, erf(x) is so close to 1 that subtraction loses precision. erfc keeps a better tiny result.
CODETOFUN NEWS
Stay Ahead in Tech
Get the latest IT news, programming updates, and technology trends directly on your phone.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
9 people found this page helpful