C programming erfc , erfcf and erfcl math.h


In C programming the <math.h> erfc,erfcf and erfcl function compute the complementary error function of the argument.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.

All the functions are the same,they compute the complementary error functions of the argument.The 1st,2nd and the 3rd function have the same name i.e.’erfc’.The 4th and 5th function have different names.What does having a different names mean is explained in detail below.

Some points to note:

i) erfc(x) is same as, 1-erf(x) = C math.h erfc,erfcf and erfcl function.

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.

Link :C programming erf,erff and erfl math.h

Code example

double d=12.234 , x1=2e200 ;

float f=12.234 ;

long double ld=12.234 ;

printf(“%lf”, erfc( d ) ) ; //calls the 2nd version
printf(“\n%f”, erfc( f ) ) ; //calls the 1st version
printf(“\n%Lf”, erfc( ld ) ) ;//calls the 3rd version

printf(“\n%lf”, erfc( x1 ) ) ;
printf(“\n%lf”, erfc( INFINITY ) ) ;

Output in Visual Studio ,

0.000000
0.000000
0.000000
0.000000
2.000000

Since x1 is very large the 4th output is 0 and for the 5th output since -INFINITY(a macro for the ‘infinity’ value) is passed 2 is returned as the output.






erfcf

The ‘erfcf‘ function is same as the 1st function.This means the parameter and return type of the function is float type.The ‘f‘ character appended to ‘erfcf‘ stands for float and it signify the parameter type and return type of the function.

Code example

float x=50.01 ;

printf(“%f”, erfc( x ) ); //Calls the 1st version
printf(“\n%f”, erfcf( 50.01) ); Calls the 4th version

Output in Visual Studio,

0.000000
0.000000


erfcl

The ‘erfcl‘ function is same as the 1st function.This means the parameter and return type of the function is long double type.The ‘l‘ character appended to ‘erfcl‘ stands for long double and it signify the parameter type and return type of the function.

Code example

long double x=50.01;

printf(“%Lf”, erfc( x ) ); //Calls the 3rd version
printf(“\n%Lf”, erfcl( 50.01 ) ); Calls the 5th version

Output,

0.000000
0.000000