Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / arctan.cpp
blob300c3e158322f3b82ec07c696de07b6e029bb42f
1 #include "stdafx.h"
2 #include "defs.h"
4 void
5 eval_arctan(void)
7 push(cadr(p1));
8 eval();
9 arctan();
12 void
13 arctan(void)
15 double d;
17 save();
19 p1 = pop();
21 if (car(p1) == symbol(TAN)) {
22 push(cadr(p1));
23 restore();
24 return;
27 if (isdouble(p1)) {
28 errno = 0;
29 d = atan(p1->u.d);
30 if (errno)
31 stop("arctan function error");
32 push_double(d);
33 restore();
34 return;
37 if (iszero(p1)) {
38 push(zero);
39 restore();
40 return;
43 if (isnegative(p1)) {
44 push(p1);
45 negate();
46 arctan();
47 negate();
48 restore();
49 return;
52 // arctan(sin(a) / cos(a)) ?
54 if (find(p1, symbol(SIN)) && find(p1, symbol(COS))) {
55 push(p1);
56 numerator();
57 p2 = pop();
58 push(p1);
59 denominator();
60 p3 = pop();
61 if (car(p2) == symbol(SIN) && car(p3) == symbol(COS) && equal(cadr(p2), cadr(p3))) {
62 push(cadr(p2));
63 restore();
64 return;
68 // arctan(1/sqrt(3)) -> pi/6
70 if (car(p1) == symbol(POWER) && equaln(cadr(p1), 3) && equalq(caddr(p1), -1, 2)) {
71 push_rational(1, 6);
72 push(symbol(PI));
73 multiply();
74 restore();
75 return;
78 // arctan(1) -> pi/4
80 if (equaln(p1, 1)) {
81 push_rational(1, 4);
82 push(symbol(PI));
83 multiply();
84 restore();
85 return;
88 // arctan(sqrt(3)) -> pi/3
90 if (car(p1) == symbol(POWER) && equaln(cadr(p1), 3) && equalq(caddr(p1), 1, 2)) {
91 push_rational(1, 3);
92 push(symbol(PI));
93 multiply();
94 restore();
95 return;
98 push_symbol(ARCTAN);
99 push(p1);
100 list(2);
102 restore();