UNPKG

521 Btext/coffeescriptView Raw
1###
2Convert complex z to polar form
3
4 Input: push z
5
6 Output: Result on stack
7
8 polar(z) = abs(z) * exp(i * arg(z))
9###
10
11
12
13Eval_polar = ->
14 push(cadr(p1))
15 Eval()
16 polar()
17
18polar = ->
19 # there are points where we turn polar
20 # representations into rect, we set a "stack flag"
21 # here to avoid that, so we don't undo the
22 # work that we are trying to do.
23 evaluatingPolar++
24 save()
25 p1 = pop()
26 push(p1)
27 abs()
28 push(imaginaryunit)
29 push(p1)
30 arg()
31 multiply()
32 exponential()
33 multiply()
34 evaluatingPolar--
35 restore()
36
37