![]() |
Oliver Maag |
This C++ code implements the normdist function as follows: NORMDIST(x,mean,standard_dev, 1)
The help of Excel only shows the formula for the implementation of: NORMDIST(x,mean,standard_dev, 0)
Many thanks to Hans Benz from COMIT who helped me a lot with the transformation from Excel to C++.
The function is available in the following languages:
static double normdist(double x, double mean, double
standard_dev)
{
double res;
double x=(x - mean) / standard_dev;
if (x == 0)
{
res=0.5;
}
else
{
double oor2pi = 1/(sqrt(double(2) *
3.14159265358979323846));
double t = 1 / (double(1) + 0.2316419 * fabs(x));
t *= oor2pi * exp(-0.5 * x * x)
* (0.31938153
+ t
* (-0.356563782
+ t
* (1.781477937
+ t
* (-1.821255978 + t * 1.330274429))));
if (x >= 0)
{
res = double(1) - t;
}
else
{
res = t;
}
}
return res;
}
private double normDist(double X,
double mean,
double sigma)
{
// Berechnungsformel wurde von Hans Benz COMIT AG ermittelt
double res = 0;
final double x = (X - mean) / sigma;
if (x == 0)
{
res = 0.5;
}
else
{
final double oor2pi = 1 / (Math.sqrt(2 *
3.14159265358979323846));
double t = 1 / (1 + 0.2316419 * Math.abs(x));
t *= oor2pi * Math.exp(-0.5 * x * x) *
(0.31938153 + t * (-0.356563782 + t *
(1.781477937 + t * (-1.821255978 + t * 1.330274429))));
if (x >= 0)
{
res = 1 - t;
}
else
{
res = t;
}
}
return res;
}
Please send your comments to
Oliver Maag
This page was last modified on 25.03.2009