MCPcopy Create free account
hub / github.com/BoevaLab/FREEC / erf

Function erf

src/normaldistr.cpp:56–93  ·  view source on GitHub ↗

Error function The integral is x - 2 | | 2 erf(x) = -------- | exp( - t ) dt. sqrt(pi) | | - 0 For 0 <= |x| < 1, erf(x) = x * P4(x**2)/Q5(x**2); otherwise erf(x) = 1 - erfc(x). ACCURACY: Relative error: arithm

Source from the content-addressed store, hash-verified

54Copyright 1984, 1987, 1988, 1992, 2000 by Stephen L. Moshier
55*************************************************************************/
56double erf(double x)
57{
58 double result;
59 double xsq;
60 double s;
61 double p;
62 double q;
63
64 s = ap::sign(x);
65 x = fabs(x);
66 if( ap::fp_less(x,0.5) )
67 {
68 xsq = x*x;
69 p = 0.007547728033418631287834;
70 p = 0.288805137207594084924010+xsq*p;
71 p = 14.3383842191748205576712+xsq*p;
72 p = 38.0140318123903008244444+xsq*p;
73 p = 3017.82788536507577809226+xsq*p;
74 p = 7404.07142710151470082064+xsq*p;
75 p = 80437.3630960840172832162+xsq*p;
76 q = 0.0;
77 q = 1.00000000000000000000000+xsq*q;
78 q = 38.0190713951939403753468+xsq*q;
79 q = 658.070155459240506326937+xsq*q;
80 q = 6379.60017324428279487120+xsq*q;
81 q = 34216.5257924628539769006+xsq*q;
82 q = 80437.3630960840172826266+xsq*q;
83 result = s*1.1283791670955125738961589031*x*p/q;
84 return result;
85 }
86 if( ap::fp_greater_eq(x,10) )
87 {
88 result = s;
89 return result;
90 }
91 result = s*(1-erfc(x));
92 return result;
93}
94
95
96/*************************************************************************

Callers 2

erfcFunction · 0.85
normaldistributionFunction · 0.85

Calls 1

erfcFunction · 0.85

Tested by

no test coverage detected