Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

# What is erfl in C?

Hassaan Waqar

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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 error functionalso known as Gauss error function in mathematics is defined as follows:

erf $z$ = $\frac{2}{\sqrt{\pi}}$ $\int_{0}^{arg} e^{-t^2} dt$

The argument to the erfl function 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:

How does erfl work?

## 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 ±$\infty$, ± $\infty$ is returned
• If the argument is NAN, NAN is 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;}

RELATED TAGS

c

CONTRIBUTOR

Hassaan Waqar 