C++ cmath erf , erff and erfl function


The C++ <cmath> erf,erff and erfl function compute the error function of the function.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.

Some points to note:
i) erf(x) is same as C++ erf,erff and erfl function

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

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

Code example

/*Passing floating point value*/
cout<< “erf(45)=” << erf(45) << endl ;

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

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

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

Output

erf(45)= 1
erf(0)= 0
erf(NAN)= nan
erf(INFINITY)= 1






erff and erfl

*Note

i)The 4th version erff is same as the 1st version float erf(float).The ‘f‘ character appended to ‘erff’ stands for ‘float’ which signify the argument type and return type of the function.

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

Code example

#include <typeinfo>

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

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

Output

*erff
f
f
*erfl
e (means ‘long double’)
e (means ‘long double’)

Here is another code example.

cout<< erf( 4 ) << endl
<< erfl( 23 ) << endl ;

Output

1
1