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 |
|
65 |
|
66 | DEBUG_ARG = false
|
67 |
|
68 | Eval_arg = ->
|
69 | push(cadr(p1))
|
70 | Eval()
|
71 | arg()
|
72 |
|
73 | arg = ->
|
74 | save()
|
75 | p1 = pop()
|
76 | push(p1)
|
77 | numerator()
|
78 | yyarg()
|
79 | push(p1)
|
80 | denominator()
|
81 | yyarg()
|
82 | subtract()
|
83 | restore()
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | yyarg = ->
|
89 | save()
|
90 | p1 = pop()
|
91 |
|
92 |
|
93 | if (ispositivenumber(p1) or p1 == symbol(PI))
|
94 | if isdouble(p1) or evaluatingAsFloats
|
95 | push_double(0)
|
96 | else
|
97 | push_integer(0)
|
98 | else if (isnegativenumber(p1))
|
99 | if isdouble(p1) or evaluatingAsFloats
|
100 | push_double(Math.PI)
|
101 | else
|
102 | push(symbol(PI))
|
103 | negate()
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | else if (issymbol(p1))
|
110 | push_symbol(ARG)
|
111 | push(p1)
|
112 | list(2)
|
113 |
|
114 | else if (car(p1) == symbol(POWER) && equaln(cadr(p1), -1))
|
115 |
|
116 | if evaluatingAsFloats
|
117 | push_double(Math.PI)
|
118 | else
|
119 | push(symbol(PI))
|
120 | push(caddr(p1))
|
121 | multiply()
|
122 | else if (car(p1) == symbol(POWER) && cadr(p1) == symbol(E))
|
123 |
|
124 | push(caddr(p1))
|
125 | imag()
|
126 |
|
127 |
|
128 | else if (car(p1) == symbol(POWER) && isoneovertwo(caddr(p1)))
|
129 | if DEBUG_ARG then console.log "arg of a sqrt: " + p1
|
130 | if DEBUG_ARG then debugger
|
131 | push(cadr(p1))
|
132 | arg()
|
133 | if DEBUG_ARG then console.log " = 1/2 * " + stack[tos-1]
|
134 | push(caddr(p1))
|
135 | multiply()
|
136 | else if (car(p1) == symbol(MULTIPLY))
|
137 |
|
138 | push_integer(0)
|
139 | p1 = cdr(p1)
|
140 | while (iscons(p1))
|
141 | push(car(p1))
|
142 | arg()
|
143 | add()
|
144 | p1 = cdr(p1)
|
145 | else if (car(p1) == symbol(ADD))
|
146 |
|
147 | push(p1)
|
148 | rect()
|
149 | p1 = pop()
|
150 | push(p1)
|
151 | real()
|
152 | p2 = pop()
|
153 | push(p1)
|
154 | imag()
|
155 | p3 = pop()
|
156 | if (iszero(p2))
|
157 | if evaluatingAsFloats
|
158 | push_double(Math.PI)
|
159 | else
|
160 | push(symbol(PI))
|
161 | if (isnegative(p3))
|
162 | negate()
|
163 | else
|
164 | push(p3)
|
165 | push(p2)
|
166 | divide()
|
167 | arctan()
|
168 | if (isnegative(p2))
|
169 | if evaluatingAsFloats
|
170 | push_double(Math.PI)
|
171 | else
|
172 | push_symbol(PI)
|
173 | if (isnegative(p3))
|
174 | subtract();
|
175 | else
|
176 | add();
|
177 | else
|
178 |
|
179 | if (!iszero(get_binding(symbol(ASSUME_REAL_VARIABLES))))
|
180 |
|
181 | push_integer(0)
|
182 | else
|
183 |
|
184 |
|
185 | push_symbol(ARG)
|
186 | push(p1)
|
187 | list(2)
|
188 |
|
189 |
|
190 | restore()
|
191 |
|
192 |
|