-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclock.cpp
73 lines (59 loc) · 894 Bytes
/
clock.cpp
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
67
68
69
70
71
72
73
/* Convert complex z to clock form
Input: push z
Output: Result on stack
clock(z) = mag(z) * (-1) ^ (arg(z) / pi)
For example, clock(exp(i pi/3)) gives the result (-1)^(1/3)
*/
#include "stdafx.h"
#include "defs.h"
void
eval_clock(void)
{
push(cadr(p1));
eval();
clockform();
}
void
clockform(void)
{
save();
#if 1
p1 = pop();
push(p1);
mag();
push_integer(-1);
push(p1);
arg();
push(symbol(PI));
divide();
power();
multiply();
#else
p1 = pop();
push(p1);
mag();
push(symbol(E));
push(p1);
arg();
push(imaginaryunit);
multiply();
power();
multiply();
#endif
restore();
}
#if SELFTEST
static const char *s[] = {
"clock(exp(i pi/3))",
"(-1)^(1/3)",
"clock(exp(-i pi/3))",
"-(-1)^(2/3)",
"rect(clock(3+4*i))", // needs sin(arctan(x)) and cos(arctan(x))
"3+4*i",
};
void
test_clock(void)
{
test(__FILE__, s, sizeof s / sizeof (char *));
}
#endif