In mathematics, the error function (also called the Gauss error function) is a special function (non-elementary) of sigmoid shape that occurs in probability, statistics, and partial differential equations describing diffusion.

It’s the probability that a normal random variable with mean 0 and variance 0.5 take value between [-x, x]. It is denoted by erf(x) and calculated by:-

In **cmath** library of C++, error function has been already implemented. There are two such functions:-

**erf(x)**: This inbuilt function calculate the error function for input value of x. Parameter x which can be int or float or double. It return a double which is erf(x).-
**erfc(x)**: This inbuilt function calculate the complementary of error function for input value of x. Parameter x which can be int or float or double. It return a double which is 1 – erf(x).

`/* C++ code to use erf */` `#include <iostream> ` `#include <cmath> /* erf */ ` ` ` `using` `namespace` `std; ` ` ` `double` `findProbability(` `double` `a) ` `{ ` ` ` `double` `prob_x_a = erf(a); ` ` ` `return` `prob_x_a; ` `} ` ` ` `int` `main () ` `{ ` ` ` `double` `a = 0.25; ` ` ` `cout << ` `"probability that normal r.v "` ` ` `"X takes value between "` ` ` `<< -a << ` `" & "` `<< a << ` `" is "` ` ` `<< findProbability(a) << endl; ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

Output:

probability that normal r.v X takes value between -0.25 & 0.25 is 0.276326

Reference :

Wikipedia

This article is contributed by **Pratik Chhajer**. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- C++ Floating Point Manipulation (fmod(), remainder(), remquo() ... in cmath)
- std::cerr | Error Stream Object in C++ with Examples
- fill() and fill_n() functions in C++ STL
- Forward List in C++ | Set 1 (Introduction and Important Functions)
- Forward List in C++ | Set 2 (Manipulating Functions)
- List in C++ | Set 2 (Some Useful Functions)
- isalpha() and isdigit() functions in C with cstring examples.
- strtok() and strtok_r() functions in C with examples
- strdup() and strndup() functions in C/C++
- Builtin functions of GCC compiler
- Ceil and Floor functions in C++
- Wide char and library functions in C++
- C Library math.h functions
- abs(), labs(), llabs() functions in C/C++
- asin() and atan() functions in C/C++ with Example
- beta(), betaf() and betal() functions in C++ STL
- std::legendre, std::legendref and std::legendrel functions in C++17
- C++ Mathematical Functions
- Database Connectivity using C/C++
- Merge operations using STL in C++ | merge(), includes(), set_union(), set_intersection(), set_difference(), ., inplace_merge,