1 // $Id: erfQ.cc,v 1.3 2003/08/13 20:00:12 garren Exp $
2 // -*- C++ -*-
3 //
4 // -----------------------------------------------------------------------
5 //                             HEP Random
6 //                          --- erfQ ---
7 //                      method implementation file
8 // -----------------------------------------------------------------------
9 
10 // Contains methods that do not depend on large tables.
11 //
12 // erfQ		  (double x)
13 
14 // =======================================================================
15 // M Fischler	  - Created 1/26/00.
16 //
17 // =======================================================================
18 
19 #include "CLHEP/Random/Stat.h"
20 #include "CLHEP/Random/defs.h"
21 #include <cmath>
22 
23 namespace CLHEP {
24 
erfQ(double x)25 double HepStat::erfQ (double x) {
26 //
27 // erfQ is accurate to 7 places.
28 // See Numerical Recipes P 221
29 //
30 
31   double t, z, erfc;
32 
33   z = std::abs(x);
34   t = 1.0/(1.0+.5*z);
35 
36   erfc= t*std::exp(-z*z-1.26551223+t*(1.00002368+t*(0.37409196+t*(0.09678418+
37 	t*(-0.18628806+t*(0.27886807+t*(-1.13520398+t*(1.48851587+
38 	t*(-0.82215223+t*0.17087277 ))) ))) )));
39 
40   // (The derivation of this formula should be obvious.)
41 
42   if ( x < 0 ) erfc = 2.0 - erfc;
43 
44   return 1 - erfc;
45 
46 }
47 
48 
49 }  // namespace CLHEP
50 
51