C programming erf ,erff and erfl math.h


In C programming the <math.h> erf,erff and erfl function compute the error function of the argument.The declaration of the functions are given below.

1 float erf(float x);
2 double erf(double x);
3 long double erf(long double x);
4 float erff(float x);
5 long double erfl(long double x);

Parameters:
x -A floating point value whose error function is to be computed.

Return type
floating point – The resultant value of the error function ‘x’ computed.

All the functions are the same,they compute the error functions of the argument.The 1st,2nd and the 3rd function have the same name i.e.’erf’.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) erf(x) is same as C erf,erff and erfl math.h

ii) If ±0 is passed it returns ±0.

iii) If ‘NAN’ is passed nan is returned, if ±∞ is passed ±1 is returned.

Code example

double d=12.234 , x1=2e200 ;

float f=12.234 ;

long double ld=12.234 ;

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

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

Output in Visual Studio ,

1.000000
1.000000
1.000000
1.000000
1.000000

All the output are 1.






erff

The ‘erff‘ 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 ‘erff‘ stands for float and it signify the parameter type and return type of the function.

Code example

float x=50.01 ;

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

Output in Visual Studio,

1.000000
1.000000


erfl

The ‘erfl‘ 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 ‘erfl‘ 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”, erf( x ) ); //Calls the 3rd version
printf(“\n%Lf”, erfl( 50.01 ) ); Calls the 5th version

Output,

1.000000
1.000000