Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / erfc.cpp
blobdc8453050dd95e9c6be0b121c9a635425f054863
1 //-----------------------------------------------------------------------------
2 //
3 // Author : philippe.billet@noos.fr
4 //
5 // erfc(x)
6 //
7 // GW Added erfc() from Numerical Recipes in C
8 //
9 //-----------------------------------------------------------------------------
11 #include "stdafx.h"
12 #include "defs.h"
13 static void yyerfc(void);
15 void
16 eval_erfc(void)
18 push(cadr(p1));
19 eval();
20 yerfc();
23 void
24 yerfc(void)
26 save();
27 yyerfc();
28 restore();
31 static void
32 yyerfc(void)
34 double d;
36 p1 = pop();
38 if (isdouble(p1)) {
39 d = erfc(p1->u.d);
40 push_double(d);
41 return;
44 push_symbol(ERFC);
45 push(p1);
46 list(2);
47 return;
50 // from Numerical Recipes in C
52 #ifndef LINUX
53 double
54 erfc(double x)
56 double t, z, ans;
57 z = fabs(x);
58 t = 1.0 / (1.0 + 0.5 * z);
60 ans=t*exp(-z*z-1.26551223+t*(1.00002368+t*(0.37409196+t*(0.09678418+
61 t*(-0.18628806+t*(0.27886807+t*(-1.13520398+t*(1.48851587+
62 t*(-0.82215223+t*0.17087277)))))))));
64 return x >= 0.0 ? ans : 2.0-ans;
66 #endif
68 #if SELFTEST
70 static char *s[] = {
72 "erfc(a)",
73 "erfc(a)",
75 "erfc(0.0)",
76 "1",
78 "float(erfc(0))",
79 "1",
80 #if 0
81 "float(erfc(1))",
82 "0.157299",
83 #endif
86 void
87 test_erfc(void)
89 test(__FILE__, s, sizeof s / sizeof (char *));
92 #endif