eigenmath/numerator.cpp

74 lines
846 B
C++
Raw Permalink Normal View History

2005-06-25 21:29:07 +02:00
#include "stdafx.h"
#include "defs.h"
void
eval_numerator(void)
{
push(cadr(p1));
eval();
numerator();
}
void
numerator(void)
{
int h;
save();
p1 = pop();
2005-06-30 18:11:36 +02:00
if (car(p1) == symbol(ADD)) {
push(p1);
rationalize();
p1 = pop();
}
2005-06-25 21:29:07 +02:00
if (car(p1) == symbol(MULTIPLY)) {
h = tos;
p1 = cdr(p1);
while (iscons(p1)) {
push(car(p1));
numerator();
p1 = cdr(p1);
}
multiply_all(tos - h);
2005-08-06 22:57:37 +02:00
} else if (isrational(p1)) {
2005-06-25 21:29:07 +02:00
push(p1);
mp_numerator();
2005-06-30 02:56:12 +02:00
} else if (car(p1) == symbol(POWER) && isnegativeterm(caddr(p1)))
2005-06-25 21:29:07 +02:00
push(one);
2005-06-30 02:56:12 +02:00
else
push(p1);
2005-06-25 21:29:07 +02:00
restore();
}
2007-05-08 16:57:30 +02:00
#if SELFTEST
2005-06-25 21:29:07 +02:00
static char *s[] = {
"numerator(2/3)",
"2",
"numerator(x)",
"x",
"numerator(1/x)",
"1",
"numerator(a+b)",
"a+b",
"numerator(1/a+1/b)",
2005-06-30 18:11:36 +02:00
"a+b",
2005-06-25 21:29:07 +02:00
};
void
test_numerator(void)
{
test(__FILE__, s, sizeof s / sizeof (char *));
2005-06-30 02:56:12 +02:00
}
2007-05-08 16:57:30 +02:00
#endif