eigenmath/clock.cpp

74 lines
888 B
C++
Raw Permalink Normal View History

2007-08-25 19:04:21 +02:00
/* Convert complex z to clock form
2007-05-09 02:06:24 +02:00
2007-08-25 19:04:21 +02:00
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)
*/
2007-05-09 02:06:24 +02:00
#include "stdafx.h"
#include "defs.h"
void
eval_clock(void)
{
push(cadr(p1));
eval();
2007-08-25 19:17:49 +02:00
clockform();
2007-08-20 04:16:50 +02:00
}
void
2007-08-25 19:17:49 +02:00
clockform(void)
2007-08-20 04:16:50 +02:00
{
save();
#if 1
2007-05-09 02:06:24 +02:00
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
2007-08-20 04:16:50 +02:00
restore();
2007-05-09 02:06:24 +02:00
}
#if SELFTEST
static 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