Cumulative Normal Distribution Function in C/C++

Tyler Brock picture Tyler Brock · Feb 24, 2010 · Viewed 67.2k times · Source

I was wondering if there were statistics functions built into math libraries that are part of the standard C++ libraries like cmath. If not, can you guys recommend a good stats library that would have a cumulative normal distribution function? Thanks in advance.

More specifically, I am looking to use/create a cumulative distribution function.

Answer

JFS picture JFS · Sep 13, 2013

Theres is no straight function. But since the gaussian error function and its complementary function is related to the normal cumulative distribution function (see here, or here) we can use the implemented c-function erfc (complementary error function):

double normalCDF(double value)
{
   return 0.5 * erfc(-value * M_SQRT1_2);
}

Which considers the relation of erfc(x) = 1-erf(x) with M_SQRT1_2 = √0,5.

I use it for statistical calculations and it works great. No need for using coefficients.