C erfc() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math.h

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.

C
erfc(1.0);
CallWhat 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
C
double erfc(double x);
float erfcf(float x);
long double erfcl(long double x);

Parameters

ParameterDescription
xRequired. The double argument to the complementary error function.

Return Value

Return ValueDescription
doubleerfc(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.

C
#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;
}

How It Works

  1. Include math.h. That declares erfc.
  2. Zero input. erfc(0) is 1.
  3. Mid values. Results shrink as x grows.
  4. 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.

C
#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;
}

How It Works

  1. Choose a large x. 6.0 makes erf very close to 1.
  2. Subtract from 1. Floating-point can lose digits.
  3. Call erfc. Designed for this complementary case.
  4. Compare formats. Scientific notation shows the tiny scale.

Example 3 — Simple Tail Style Print

Print how fast erfc falls as x increases.

C
#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;
}

How It Works

  1. Loop x from 0 to 4. Integer steps are easy to read.
  2. Call erfc each time. Print in scientific form.
  3. Watch the drop. Values fall toward 0 quickly.
  4. 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.

Next: exp()

Raise e to the power of a floating-point exponent.

exp() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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