libstatcalc.cpp
// NORMINV
// Code for NORMINV: Inverse normal cumulative distribution 
// aka. quantile function
// http://www.wilmott.com/messageview.cfm?catid=10&threadid=38771
// sjoo
/*
 *     Compute the quantile function for the normal distribution.
 *
 *     For small to moderate probabilities, algorithm referenced
 *     below is used to obtain an initial approximation which is
 *     polished with a final Newton step.
 *
 *     For very large arguments, an algorithm of Wichura is used.
 *
 *  REFERENCE
 *
 *     Beasley, J. D. and S. G. Springer (1977).
 *     Algorithm AS 111: The percentage points of the normal distribution,
 *     Applied Statistics, 26, 118-121.
 *
 *     Wichura, M.J. (1988).
 *     Algorithm AS 241: The Percentage Points of the Normal Distribution.
 *     Applied Statistics, 37, 477-484.
 */
NORMINV
Code for NORMINV: Inverse normal cumulative distribution
aka.

Compute the quantile function for the normal distribution.

For small to moderate probabilities, algorithm referenced
below is used to obtain an initial approximation which is
polished with a final Newton step.

For very large arguments, an algorithm of Wichura is used.

REFERENCE

Beasley, J. D. and S. G.


NORMINV Code for NORMINV : Inverse normal cumulative distribution aka . Compute the quantile function for the normal distribution . For small to moderate probabilities algorithm referenced below is used to obtain an initial approximation which is polished with a final Newton step . For very large arguments an algorithm of Wichura is used . REFERENCE Beasley J . D . and S . G .
double expm1(double x) {
	double y, a = fabs(x);
	if (a < DBL_EPSILON)
		return x;
	if (a > 0.697)
		return exp(x) - 1; 
	if (a > 1e-8)
		y = exp(x) - 1;
	else
		y = (x / 2 + 1) * x;
	y -= (1 + y) * (log(1 + y) - x);
	return y;
}
double expm1 ( double x ) { double y , a = fabs ( x ) ; if ( a < DBL_EPSILON ) return x ; if ( a > 0.697 ) return exp ( x ) - 1 ; if ( a > 1e-8 ) y = exp ( x ) - 1 ; else y = ( x / 2 + 1 ) * x ; y -= ( 1 + y ) * ( log ( 1 + y ) - x ) ; return y ; }
NORMINV
Code for NORMINV: Inverse normal cumulative distribution
aka.
NORMINV Code for NORMINV : Inverse normal cumulative distribution aka .
/* negligible cancellation */ /* Taylor expansion, more accurate in this range */ /* Newton step for solving   log(1 + y) = x   for y : */ /* WARNING: does not work for y ~ -1: bug in 1.5.0 */