C++ Math erfc()

Last Updated : 18 May 2026

Math erfc() Function

In C++, the erfc() function is defined in the <cmath> or <math.h> header file and is used to calculate the complementary error function value of a given number. The complementary error function is mathematically defined as:

erfc⁡(x)=1−erf⁡(x)\operatorname{erfc}(x)=1-\operatorname{erf}(x)erfc(x)=1−erf(x)

The erfc() function supports float, double, long double, and integer values.

Syntax

It has the following syntax.

Parameters

x: It is a floating point value.

Return value

It returns the complementary error function value of x.

ParameterReturn value
x=+∞+0
x= -∞2
x=nannan

Examples of erfc() Function

Here, we are going to discuss several examples to demonstrate the erfc() Function.

Example 1: Calculate the Complementary Error Function Value of Positive Infinity

This example demonstrates how the erfc() function behaves when the input value is positive infinity.

Output:

Value of x is : inf
erfc(x) : 0

Explanation:

In the above example, the value of x is positive infinite. Therefore, the function erfc() returns 0 value.

Example 2: Calculate the Complementary Error Function Value of Negative Infinity

This example demonstrates how the erfc() function behaves when the input value is negative infinity.

Output:

Value of x is : -inf
erfc(x) : 2

Explanation:

In the above example, the value of x is negative infinite. Therefore, the function erfc() returns 2.

Example 3: Calculate the Complementary Error Function Value of NaN

This example demonstrates how the erfc() function behaves when the input value is NaN (Not a Number).

Output:

Value of x is : -nan
erfc(x) : -nan

Explanation:

In the above example, the value of x is nan. Therefore, the function erfc() returns nan.