# C++ cmath erfc , erfcf and erfcl function

The C++ <cmath> erfc,erfcf and erfcl function compute the complementary error function of the given value.The declaration of the functions are given below.

1 float erfc(float x);
2 double erfc(double x);
3 long double erfc(long double x);
4 float erfcf(float x);
5 long double erfcl(long double x);

Parameters:
x -The value whose complementary error is to be computed.

Return type
floating point -The complementary error function of x.

Some points to note:

i) erfc(x) is same as, 1-erf(x) = .

ii) If x is very large and -ve the function gives 2 and if +ve it gives 0.

iii) If x is very samll +ve or -ve it gives 1.

iv) erfc(±0) gives 1.

v) erfc(-∞) gives 2 and erf(+∞) gives 0.

vi) erfc(NAN) gives ‘nan’.

vii) If integer is passed the 2nd version is called-the double version.

Code example

/*Passing floating point value*/
cout<*< “erfc(23)=” << erfc(23) << endl;

/*Passing very large value*/
cout<*< “erfc(3e50)=” << erfc(3e50) << endl;

/*Passing 0*/
cout<*< “erfc(0)=” << erfc(0) << endl;

/*Passing NAN*/
cout<*< “erfc(NAN)=” << erfc(NAN) << endl;

/*Passing INFINITY*/
cout<*< “erfc(-INFINITY)=” << erfc(-INFINITY) << endl;

Output

erfc(23)=4.44127e-232
erfc(3e50)=0
erfc(0)=1
erfc(NAN)=nan
erfc(-INFINITY)=2

#### erfcf and erfcl

*Note

i)The 4th version erfcf is same as the 1st version float erfc(float).The last character ‘f‘ in ‘erfcf’ stands for ‘float’ which signify the argument and return type of the function.

ii)The 5th version erfcl is same as the 3rd version long double erfc(long double).The last character ‘l‘ in ‘erfcl’ stands for ‘long double’ which signify the argument and return type of the function.

Code example

#include <typeinfo>

/*erfcf */
cout<< “*erfcf\n”;
float f=2;
cout<< typeid( erfcf(2) ).name() << endl /*identify type of erfcf retunred value */
<< typeid( erfc(f) ).name() << endl; /*identify type of erfc(float) returned value */

/*erfcl*/
cout<< “*erfcl\n”;
long double ld=2;
cout<< typeid( erfcl(2) ).name() << endl /*indentify type of erfcl returned value */
<< typeid( erfc(ld) ).name() << endl; /*identify type of erfc(long double) returned value*/

Output

*erfcf
f
f
*erfcl
e (means ‘long double’)
e (means ‘long double’)

Here is another program which yields the same output when ‘erfc’ or ‘erfcf’ or ‘erfcl’ is used.

cout<< erfc(12) << endl
<< erfcl(12) ;

Output

1.35626e-064
1.35626e-064