-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy patherfc.coffee
65 lines (49 loc) · 925 Bytes
/
erfc.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#-----------------------------------------------------------------------------
#
# Author : philippe.billet@noos.fr
#
# erfc(x)
#
# GW Added erfc() from Numerical Recipes in C
#
#-----------------------------------------------------------------------------
Eval_erfc = ->
push(cadr(p1))
Eval()
yerfc()
yerfc = ->
save()
yyerfc()
restore()
yyerfc = ->
d = 0.0
p1 = pop()
if (isdouble(p1))
d = erfc(p1.d)
push_double(d)
return
push_symbol(ERFC)
push(p1)
list(2)
return
# from Numerical Recipes in C
#ifndef LINUX
erfc = (x) ->
t = 0.0
z = 0.0
ans = 0.0
z = Math.abs(x)
t = 1.0 / (1.0 + 0.5 * z)
ans=t*Math.exp(-z*z-1.26551223+t*(1.00002368+t*(0.37409196+t*(0.09678418+
t*(-0.18628806+t*(0.27886807+t*(-1.13520398+t*(1.48851587+
t*(-0.82215223+t*0.17087277)))))))))
if x >= 0.0
return ans
else
return 2.0-ans
#endif
###
# commented-out test
"float(erfc(1))",
"0.157299",
###