C++ Math erfc
The erfc function calculates the value of the complementary error function for a given parameter.
Suppose a number is 'x' :
erfc(x) = 1-erf(x);
Syntax
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.
#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:
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.
#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:
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.
#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:
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.