What is erff in C?
The erff function is defined in the <math.h> header file in C. It takes in a single parameter: a float value. It then computes the error function of the given argument and returns a value of type float.
The
erf =
The argument to the
erfffunction serves as the upper limit in the integral above.
The error function is widely used in probability and statistics. It integrates the normal distribution and gives the probability that a normally distributed random variable Y (with mean 0 and variance ½) falls into the range [−x, x].
The illustration below shows how erff function works:
Declaration
The erff function is defined as follows:
float erff(float arg);
It takes in a single value of type float and computes its error function. It then returns the answer of type float.
Error handling
The erff function returns special values for certain arguments:
- If the argument is ±0, ±0 is returned
- If the argument is ±, ± is returned
- If the argument is
NAN,NANis returned
Examples
The following code snippet shows how we can use the erff function:
#include <stdio.h> // Including header file for printf function#include <math.h> // Including header file for erf functionint main (){float param, result;param = 4.0;result = erff(param);printf("erff (%f) = %f\n", param, result);return 0;}
The following code snippet shows how error handling in erff function works:
#include <stdio.h> // Including header file for printf function#include <math.h> // Including header file for erf functionint main (){printf("erff (%f) = %f\n", 0.0, erff(0.0));return 0;}
Free Resources