This commit is contained in:
George Weigt 2006-02-07 13:35:04 -07:00
parent e4f49c7543
commit a67c28d779
7 changed files with 53 additions and 7 deletions

View file

@ -48,7 +48,7 @@ trace.o charpoly.o hermite.o laguerre.o legendre.o degree.o divisors.o \
vectorize.o variables.o test.o selftest.o numerator.o denominator.o simfac.o \
besselj.o bessely.o carac.o convolution.o dirac.o erf.o erfc.o summarize.o \
fourier.o gamma.o heaviside.o invfourier.o sgn.o cofactor.o adj.o \
tchebychevT.o tchebychevU.o arg.o imag.o mag.o real.o rect.o
tchebychevT.o tchebychevU.o arg.o imag.o mag.o real.o rect.o divpoly.o
math : $(objects)
$(CXX) -o math $(objects) -lm

1
defs.h
View file

@ -93,6 +93,7 @@ enum {
DIRAC,
DISPLAY,
DIVISORS,
DIVPOLY,
DO,
DOT,
DRAW,

View file

@ -1,4 +1,28 @@
// Divide polynomials
#include "stdafx.h"
#include "defs.h"
void
eval_divpoly(void)
{
push(cadr(p1)); // 1st arg, p(x)
eval();
push(caddr(p1)); // 2nd arg, q(x)
eval();
push(cadddr(p1)); // 3rd arg, x
eval();
p1 = pop(); // guess?
if (p1 == symbol(NIL))
guess();
else
push(p1);
divpoly();
}
//-----------------------------------------------------------------------------
//
@ -10,18 +34,15 @@
//
// tos-1 x
//
// Output: tos-2 Quotient
//
// tos-1 Remainder
// Output: tos-1 Quotient
//
//-----------------------------------------------------------------------------
#include "defs.h"
#define DIVIDEND p1
#define DIVISOR p2
#define X p3
#define Q p4
#define QUOTIENT p5
void
divpoly(void)
@ -51,7 +72,8 @@ divpoly(void)
x = m - n;
push(zero);
push_integer(0);
QUOTIENT = pop();
while (x >= 0) {
@ -69,16 +91,34 @@ divpoly(void)
dividend[x + i] = pop();
}
push(QUOTIENT);
push(Q);
push(X);
push_integer(x);
power();
multiply();
add();
QUOTIENT = pop();
m--;
x--;
}
tos = h;
push(QUOTIENT);
restore();
}
static char *s[] = {
"divpoly(x^2+1,x)",
"x",
};
void
test_divpoly(void)
{
test(__FILE__, s, sizeof s / sizeof (char *));
}

View file

@ -103,6 +103,7 @@ eval_cons(void)
case DIRAC: eval_dirac(); break;
case DISPLAY: eval_display(); break;
case DIVISORS: eval_divisors(); break;
case DIVPOLY: eval_divpoly(); break;
case DO: eval_do(); break;
case DOT: eval_inner(); break;
case DRAW: eval_draw(); break;

View file

@ -71,6 +71,7 @@ init(void)
std_symbol("dirac", DIRAC);
std_symbol("display", DISPLAY);
std_symbol("divisors", DIVISORS);
std_symbol("divpoly", DIVPOLY);
std_symbol("do", DO);
std_symbol("dot", DOT);
std_symbol("draw", DRAW);

View file

@ -244,7 +244,9 @@ void divisors_onstack(void);
void test_divisors(void);
// divpoly.cpp
void eval_divpoly(void);
void divpoly(void);
void test_divpoly(void);
// draw.cpp
void eval_draw(void);

View file

@ -59,6 +59,7 @@ selftest(void)
test_denominator();
test_derivative();
test_dirac();
test_divpoly();
test_erf();
test_erfc();
test_expcos();