Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / real.cpp
blob21d07885eb210cd8ec6fee1a7dab5b9ce5f4b09b
1 /* Returns the real part of complex z
3 z real(z)
4 - -------
6 a + i b a
8 exp(i a) cos(a)
9 */
11 #include "stdafx.h"
12 #include "defs.h"
14 void
15 eval_real(void)
17 push(cadr(p1));
18 eval();
19 real();
22 void
23 real(void)
25 save();
26 rect();
27 p1 = pop();
28 push(p1);
29 push(p1);
30 conjugate();
31 add();
32 push_integer(2);
33 divide();
34 restore();
37 #if SELFTEST
39 static char *s[] = {
41 "real(a+i*b)",
42 "a",
44 "real(1+exp(i*pi/3))",
45 "3/2",
47 "real(i)",
48 "0",
50 "real((-1)^(1/3))",
51 "1/2",
54 void
55 test_real(void)
57 test(__FILE__, s, sizeof s / sizeof (char *));
60 #endif