Little fix after the last commit (mostly a git fail)
[eigenmath-fx.git] / degree.cpp
blobfbf4392a6d46ec0393d619cdc78e1e93475f4b3c
1 #include "stdafx.h"
2 #include "defs.h"
4 void
5 eval_degree(void)
7 push(cadr(p1));
8 eval();
9 push(caddr(p1));
10 eval();
11 p1 = pop();
12 if (p1 == symbol(NIL))
13 guess();
14 else
15 push(p1);
16 degree();
19 //-----------------------------------------------------------------------------
21 // Find the degree of a polynomial
23 // Input: tos-2 p(x)
25 // tos-1 x
27 // Output: Result on stack
29 // Note: Finds the largest numerical power of x. Does not check for
30 // weirdness in p(x).
32 //-----------------------------------------------------------------------------
34 #define POLY p1
35 #define X p2
36 #define DEGREE p3
38 void
39 degree(void)
41 save();
42 X = pop();
43 POLY = pop();
44 DEGREE = zero;
45 yydegree(POLY);
46 push(DEGREE);
47 restore();
50 void
51 yydegree(U *p)
53 if (equal(p, X)) {
54 if (iszero(DEGREE))
55 DEGREE = one;
56 } else if (car(p) == symbol(POWER)) {
57 if (equal(cadr(p), X) && isnum(caddr(p)) && lessp(DEGREE, caddr(p)))
58 DEGREE = caddr(p);
59 } else if (iscons(p)) {
60 p = cdr(p);
61 while (iscons(p)) {
62 yydegree(car(p));
63 p = cdr(p);