Math Erfc Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Erfc Function

Math Erfc Function

BLUF: Mastering Math Erfc Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Erfc Function

C++ is renowned for its efficiency. Learn how Math Erfc Function enables low-level control and high-performance computing in the tutorial below.

C++ Math erfc

The erfc function calculates the value of the complementary error function for a given parameter.

Suppose a number is 'x' :

Example

erfc(x) = 1-erf(x);

Syntax

Example

float erfc(float x) ;
double erfc(double x) ;
long double erfc(long double x) ;
double erfc(integral x);

Parameter

x : It is a floating point value.

Return value

It provides the inverse error function value of x.

Parameter Return value
x=+∞ +0
x= -∞ 2
x=nan nan

Example 1

Let's examine a basic scenario where the value of x approaches positive infinity.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
     float x= 2.0/0.0;
     cout<<"Value of x is : "<<x<<'\n';
     cout<<"erfc(x) : "<<erfc(x);
     return 0;
}

Output:

Output

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

In the aforementioned scenario, the variable x holds a positive infinite value. Consequently, the erfc function yields a result of 0.

Example 2

Let's examine a basic scenario where the value of x approaches negative infinity.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
     float x= -1.0/0.0;
     cout<<"Value of x is : "<<x<<'\n';
     cout<<"erfc(x) : "<<erfc(x);
     return 0;
}

Output:

Output

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

In the given example, the value of x is negative infinity. As a result, the erfc function yields a result of 2.

Example 3

Let's consider a basic scenario where the value of x is NaN.

Example

#include <iostream>
#include<math.h>
using namespace std;
int main()
{
     float x= sqrt(-2);
     cout<<"Value of x is : "<<x<<'\n';
     cout<<"erfc(x) : "<<erfc(x);
     return 0;
}

Output:

Output

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

In the previous example, the value of x is NaN. Consequently, the erfc function will yield NaN as well.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience