2004-03-03 21:24:06 +01:00
|
|
|
#include "stdafx.h"
|
2006-02-11 00:39:56 +01:00
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
eval_degree(void)
|
|
|
|
{
|
|
|
|
push(cadr(p1));
|
|
|
|
eval();
|
|
|
|
push(caddr(p1));
|
|
|
|
eval();
|
|
|
|
p1 = pop();
|
|
|
|
if (p1 == symbol(NIL))
|
|
|
|
guess();
|
|
|
|
else
|
|
|
|
push(p1);
|
|
|
|
degree();
|
|
|
|
}
|
2004-03-03 21:24:06 +01:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Find the degree of a polynomial
|
|
|
|
//
|
|
|
|
// Input: tos-2 p(x)
|
|
|
|
//
|
|
|
|
// tos-1 x
|
|
|
|
//
|
|
|
|
// Output: Result on stack
|
|
|
|
//
|
|
|
|
// Note: Finds the largest numerical power of x. Does not check for
|
|
|
|
// weirdness in p(x).
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define POLY p1
|
|
|
|
#define X p2
|
|
|
|
#define DEGREE p3
|
|
|
|
|
|
|
|
void
|
|
|
|
degree(void)
|
|
|
|
{
|
|
|
|
save();
|
|
|
|
X = pop();
|
|
|
|
POLY = pop();
|
2004-06-25 22:45:15 +02:00
|
|
|
DEGREE = zero;
|
2006-02-11 00:39:56 +01:00
|
|
|
yydegree(POLY);
|
2004-03-03 21:24:06 +01:00
|
|
|
push(DEGREE);
|
|
|
|
restore();
|
|
|
|
}
|
|
|
|
|
2006-02-11 00:39:56 +01:00
|
|
|
void
|
|
|
|
yydegree(U *p)
|
2004-03-03 21:24:06 +01:00
|
|
|
{
|
|
|
|
if (equal(p, X)) {
|
|
|
|
if (iszero(DEGREE))
|
2004-06-25 22:45:15 +02:00
|
|
|
DEGREE = one;
|
2004-03-03 21:24:06 +01:00
|
|
|
} else if (car(p) == symbol(POWER)) {
|
|
|
|
if (equal(cadr(p), X) && isnum(caddr(p)) && lessp(DEGREE, caddr(p)))
|
|
|
|
DEGREE = caddr(p);
|
|
|
|
} else if (iscons(p)) {
|
|
|
|
p = cdr(p);
|
|
|
|
while (iscons(p)) {
|
2006-02-11 00:39:56 +01:00
|
|
|
yydegree(car(p));
|
2004-03-03 21:24:06 +01:00
|
|
|
p = cdr(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|