UNPKG

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