private static double NormalCDFInverse(double p)
{
if (p <= 0.0 || p >= 1.0)
{
string msg = String.Format("Invalid input argument: {0}.", p);
throw new ArgumentOutOfRangeException(msg);
}
// See article above for explanation of this section.
if (p < 0.5)
{
// F^-1(p) = - G^-1(p)
return -RationalApproximation(Math.Sqrt(-2.0 * Math.Log(p)));
}
// F^-1(p) = G^-1(1-p)
return RationalApproximation(Math.Sqrt(-2.0 * Math.Log(1.0 - p)));
}