2005-06-25 21:29:07 +02:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
eval_denominator(void)
|
|
|
|
{
|
|
|
|
push(cadr(p1));
|
|
|
|
eval();
|
|
|
|
denominator();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
denominator(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));
|
|
|
|
denominator();
|
|
|
|
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_denominator();
|
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(p1);
|
|
|
|
reciprocate();
|
2005-06-30 02:56:12 +02:00
|
|
|
} else
|
|
|
|
push(one);
|
2005-06-25 21:29:07 +02:00
|
|
|
|
|
|
|
restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *s[] = {
|
|
|
|
|
|
|
|
"denominator(2/3)",
|
|
|
|
"3",
|
|
|
|
|
|
|
|
"denominator(x)",
|
|
|
|
"1",
|
|
|
|
|
|
|
|
"denominator(1/x)",
|
|
|
|
"x",
|
|
|
|
|
|
|
|
"denominator(a+b)",
|
|
|
|
"1",
|
|
|
|
|
|
|
|
"denominator(1/a+1/b)",
|
2005-06-30 18:11:36 +02:00
|
|
|
"a*b",
|
2005-06-25 21:29:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
test_denominator(void)
|
|
|
|
{
|
|
|
|
test(__FILE__, s, sizeof s / sizeof (char *));
|
2005-06-30 02:56:12 +02:00
|
|
|
}
|