2006-02-10 20:24:36 +01:00
|
|
|
/* polar(z) = mag(z) * (-1) ^ (arg(z) / pi)
|
|
|
|
|
|
|
|
For example polar(exp(i pi/3)) gives the result (-1)^(1/3)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
eval_polar(void)
|
|
|
|
{
|
|
|
|
push(cadr(p1));
|
|
|
|
eval();
|
|
|
|
p1 = pop();
|
|
|
|
push(p1);
|
|
|
|
mag();
|
|
|
|
push_integer(-1);
|
|
|
|
push(p1);
|
|
|
|
arg();
|
|
|
|
push(symbol(PI));
|
|
|
|
divide();
|
|
|
|
power();
|
|
|
|
multiply();
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *s[] = {
|
|
|
|
|
|
|
|
"polar(exp(i pi/3))",
|
|
|
|
"(-1)^(1/3)",
|
|
|
|
|
|
|
|
"polar(exp(-i pi/3))",
|
|
|
|
"-(-1)^(2/3)",
|
2006-02-11 21:11:26 +01:00
|
|
|
|
|
|
|
"rect(polar(3+4*i))", // needs sin(arctan(x)) and cos(arctan(x))
|
|
|
|
"3+4*i",
|
2006-02-10 20:24:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
test_polar(void)
|
|
|
|
{
|
|
|
|
test(__FILE__, s, sizeof s / sizeof (char *));
|
|
|
|
}
|