2007-08-25 19:04:21 +02:00
|
|
|
/* Convert complex z to polar form
|
|
|
|
|
|
|
|
Input: push z
|
|
|
|
|
|
|
|
Output: Result on stack
|
|
|
|
|
|
|
|
polar(z) = mag(z) * exp(i * arg(z))
|
|
|
|
*/
|
2006-02-10 20:24:36 +01:00
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
eval_polar(void)
|
|
|
|
{
|
2006-09-18 21:16:44 +02:00
|
|
|
push(cadr(p1));
|
|
|
|
eval();
|
2007-08-25 19:04:21 +02:00
|
|
|
polar();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
polar(void)
|
|
|
|
{
|
|
|
|
save();
|
2006-09-18 21:16:44 +02:00
|
|
|
p1 = pop();
|
|
|
|
push(p1);
|
|
|
|
mag();
|
2007-05-09 02:06:24 +02:00
|
|
|
push(imaginaryunit);
|
2006-09-18 21:16:44 +02:00
|
|
|
push(p1);
|
|
|
|
arg();
|
|
|
|
multiply();
|
2007-05-09 02:06:24 +02:00
|
|
|
exponential();
|
2006-09-18 21:16:44 +02:00
|
|
|
multiply();
|
2007-08-25 19:04:21 +02:00
|
|
|
restore();
|
2006-02-10 20:24:36 +01:00
|
|
|
}
|
|
|
|
|
2007-05-08 16:57:30 +02:00
|
|
|
#if SELFTEST
|
|
|
|
|
2006-02-10 20:24:36 +01:00
|
|
|
static char *s[] = {
|
|
|
|
|
2007-05-09 02:06:24 +02:00
|
|
|
"polar(1+i)",
|
|
|
|
"2^(1/2)*exp(1/4*i*pi)",
|
2006-02-11 21:11:26 +01:00
|
|
|
|
2007-05-09 04:45:06 +02:00
|
|
|
"polar(-1+i)",
|
|
|
|
"2^(1/2)*exp(3/4*i*pi)",
|
|
|
|
|
|
|
|
"polar(-1-i)",
|
|
|
|
"2^(1/2)*exp(-3/4*i*pi)",
|
2007-05-09 02:06:24 +02:00
|
|
|
|
2007-05-09 04:45:06 +02:00
|
|
|
"polar(1-i)",
|
|
|
|
"2^(1/2)*exp(-1/4*i*pi)",
|
|
|
|
|
|
|
|
"rect(polar(3+4*i))",
|
|
|
|
"3+4*i",
|
2007-05-09 02:06:24 +02:00
|
|
|
|
2007-05-09 04:45:06 +02:00
|
|
|
"rect(polar(-3+4*i))",
|
|
|
|
"-3+4*i",
|
2007-05-09 02:06:24 +02:00
|
|
|
|
2007-05-09 04:45:06 +02:00
|
|
|
"rect(polar(3-4*i))",
|
|
|
|
"3-4*i",
|
2007-05-09 02:06:24 +02:00
|
|
|
|
2007-05-09 04:45:06 +02:00
|
|
|
"rect(polar(-3-4*i))",
|
|
|
|
"-3-4*i",
|
2006-02-10 20:24:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
test_polar(void)
|
|
|
|
{
|
|
|
|
test(__FILE__, s, sizeof s / sizeof (char *));
|
|
|
|
}
|
2007-05-08 16:57:30 +02:00
|
|
|
|
|
|
|
#endif
|