eigenmath/real.cpp

61 lines
560 B
C++
Raw Permalink Normal View History

2005-10-12 01:25:25 +02:00
/* Returns the real part of complex z
z real(z)
- -------
a + i b a
exp(i a) cos(a)
*/
#include "stdafx.h"
#include "defs.h"
void
eval_real(void)
{
push(cadr(p1));
eval();
real();
}
void
real(void)
{
save();
rect();
p1 = pop();
push(p1);
push(p1);
conjugate();
add();
push_integer(2);
divide();
restore();
}
2005-10-09 23:24:06 +02:00
2007-05-08 16:57:30 +02:00
#if SELFTEST
2005-10-09 23:24:06 +02:00
static char *s[] = {
"real(a+i*b)",
"a",
"real(1+exp(i*pi/3))",
"3/2",
"real(i)",
"0",
"real((-1)^(1/3))",
"1/2",
};
2005-10-08 04:20:34 +02:00
void
2005-10-09 23:24:06 +02:00
test_real(void)
2005-10-08 04:20:34 +02:00
{
2005-10-09 23:24:06 +02:00
test(__FILE__, s, sizeof s / sizeof (char *));
2005-10-08 04:20:34 +02:00
}
2007-05-08 16:57:30 +02:00
#endif