C++ Math erfc
The erfc function computes the complementary error function value of a parameter passed to the function.
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 returns the complementary error function value of x.
| Parameter | Return value |
|---|---|
| x=+∞ | +0 |
| x= -∞ | 2 |
| x=nan | nan |
Example 1
Let's see the simple example when the value of x is +∞.
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 above example, the value of x is positive infinite. Therefore, the function erfc returns 0 value.
Example 2
Let's see the simple example when the value of x is -∞.
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 above example, the value of x is negative infinite. Therefore, the function erfc returns 2.
Example 3
Let's see the simple example when 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 above example, the value of x is nan. Therefore, the function erfc returns nan.