function p = ltpnorm(z)
%LTPNORM Lower tail probability for standard normal distribution.
%
%   P = LTPNORM(Z) returns the lower tail probability for the standard normal
%   distribution function.  I.e., it returns P = Pr{X < Z}, where X has a
%   standard normal distribution.

%   Author:      Peter J. Acklam
%   Time-stamp:  2003-04-13 11:45:27 +0200
%   E-mail:      pjacklam@online.no
%   URL:         http://home.online.no/~pjacklam

   %p = 0.5 * (1 + erf(z/sqrt(2)));
   p = 0.5 * erfc(-z / sqrt(2));

   % fix up for a bug in erfcore (MATLAB R11 and earlier)
   p(isnan(z)) = NaN;
