What is erfl in C?
The erfl function is defined in the <tgmath.h> header file in C. It takes in a single parameter: a long double value. It then computes the error function of the given argument and returns a value of type long double.
The
erf =
The argument to the
erflfunction serves as the upper limit in the integral above.
The error function is often 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 the erfl function works:
Declaration
The erfl function is defined as follows:
long double erfl(long double arg);
It takes in a single value of type long double and computes its error function. It then returns the answer of type long double.
Error handling
The erfl 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 erfl function:
#include <stdio.h> // Including header file for printf function#include <math.h> // Including header file for erf functionint main (){long double param, result;param = 2.0;result = erfl(param);printf("erfl (%Lf) = %Lf\n", param, result);return 0;}
The following code snippet shows how error handling in the erfl function works:
#include <stdio.h> // Including header file for printf function#include <math.h> // Including header file for erf functionint main (){long double param = 0.0;printf("erfl (%Lf) = %Lf\n", param, erfl(0.0));return 0;}
Free Resources