Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / imag.cpp
blobd3ebce236709a6c9f9bfa89f4ecdf87bd2cfb1c6
1 /* Returns the coefficient of the imaginary part of complex z
3 z imag(z)
4 - -------
6 a + i b b
8 exp(i a) sin(a)
9 */
11 #include "stdafx.h"
12 #include "defs.h"
14 void
15 eval_imag(void)
17 push(cadr(p1));
18 eval();
19 imag();
22 void
23 imag(void)
25 save();
26 rect();
27 p1 = pop();
28 push(p1);
29 push(p1);
30 conjugate();
31 subtract();
32 push_integer(2);
33 divide();
34 push(imaginaryunit);
35 divide();
36 restore();
39 #if SELFTEST
41 static char *s[] = {
43 "imag(a+i*b)",
44 "b",
46 "imag(1+exp(i*pi/3))",
47 "1/2*3^(1/2)",
49 "imag(i)",
50 "1",
52 "imag((-1)^(1/3))",
53 "1/2*3^(1/2)",
55 "imag(-i)",
56 "-1",
59 void
60 test_imag(void)
62 test(__FILE__, s, sizeof s / sizeof (char *));
65 #endif