Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / numerator.cpp
blob8a58972b09fa1830ffa5bd57e184a1d809af4c2e
1 #include "stdafx.h"
2 #include "defs.h"
4 void
5 eval_numerator(void)
7 push(cadr(p1));
8 eval();
9 numerator();
12 void
13 numerator(void)
15 int h;
17 save();
19 p1 = pop();
21 if (car(p1) == symbol(ADD)) {
22 push(p1);
23 rationalize();
24 p1 = pop();
27 if (car(p1) == symbol(MULTIPLY)) {
28 h = tos;
29 p1 = cdr(p1);
30 while (iscons(p1)) {
31 push(car(p1));
32 numerator();
33 p1 = cdr(p1);
35 multiply_all(tos - h);
36 } else if (isrational(p1)) {
37 push(p1);
38 mp_numerator();
39 } else if (car(p1) == symbol(POWER) && isnegativeterm(caddr(p1)))
40 push(one);
41 else
42 push(p1);
44 restore();
47 #if SELFTEST
49 static char *s[] = {
51 "numerator(2/3)",
52 "2",
54 "numerator(x)",
55 "x",
57 "numerator(1/x)",
58 "1",
60 "numerator(a+b)",
61 "a+b",
63 "numerator(1/a+1/b)",
64 "a+b",
67 void
68 test_numerator(void)
70 test(__FILE__, s, sizeof s / sizeof (char *));
73 #endif