STK++ 1.0
STK_Funct_normal_raw.cpp
Go to the documentation of this file.
00001 /*--------------------------------------------------------------------*/
00002 /*  Copyright (C) 2004-2007  Serge Iovleff
00003     
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU Lesser General Public License as
00006     published by the Free Software Foundation; either version 2 of the
00007     License, or (at your option) any later version.
00008     
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU Lesser General Public License for more details.
00013     
00014     You should have received a copy of the GNU Lesser General Public
00015     License along with this program; if not, write to the
00016     Free Software Foundation, Inc.,
00017     59 Temple Place,
00018     Suite 330,
00019     Boston, MA 02111-1307
00020     USA
00021     
00022     Contact : Serge.Iovleff@stkpp.org
00023 */
00024 
00025 /*
00026  Cephes Math Library Release 2.2:  June, 1992
00027  Copyright 1984, 1987, 1988, 1992 by Stephen L. Moshier
00028  Direct inquiries to 30 Frost Street, Cambridge, MA 02140
00029  */
00030 
00031 /*
00032  * Project:  Analysis
00033  * Purpose:  Implementation of the normal functions
00034  * Author:   Serge Iovleff, serge.iovleff@stkpp.org
00035  **/
00036 
00041 #include <cmath>
00042 #include "../../STKernel/include/STK_Integer.h"
00043 #include "../../STKernel/include/STK_Real.h"
00044 #include "../../STKernel/include/STK_Misc.h"
00045 
00046 #include "../include/STK_Const_Math.h"
00047 #include "../include/STK_Funct_raw.h"
00048 
00049 namespace STK
00050 {
00051 namespace Funct
00052 {
00053 
00062 Real normal_pdf_raw(Real const& x)
00063 {
00064   return Const::_1_SQRT2PI_ * exp(-0.5 * x * x);
00065 }
00066 
00081 Real normal_cdf_raw(Real const& x)
00082 {
00083   Real t = x * Const::_1_SQRT2_;
00084   Real z = abs(t);
00085 
00086   if ( z < Const::_1_SQRT2_) return 0.5 + 0.5 * erf(t);
00087   Real y = 0.5 * erfc(z);
00088   return ( t > 0) ? 1. - y : y;
00089 }
00090 
00091 } // namespace Funct
00092   
00093 } // namespace STK