30double poly(
double *a,
long n,
double x)
33 register double sum, xp;
37 for (i = 0; i < n; i++) {
58double dpoly(
double *a,
long n,
double x) {
60 register double sum, xp;
64 for (i = 1; i < n; i++) {
84double polyp(
double *a,
long *power,
long n,
double x) {
86 register double sum, xp;
88 xp =
ipow(x, power[0]);
90 for (i = 1; i < n; i++) {
91 xp *=
ipow(x, power[i] - power[i - 1]);
111double dpolyp(
double *a,
long *power,
long n,
double x) {
113 register double sum, xp;
115 xp =
ipow(x, power[0] - 1);
116 sum = power[0] * xp * a[0];
117 for (i = 1; i < n; i++) {
118 xp *=
ipow(x, power[i] - power[i - 1]);
119 sum += power[i] * xp * a[i];
144 solution[0] = -c / b;
147 if ((det = b * b - 4 * a * c) < 0)
150 solution[0] = -b / a;
153 solution[0] = (-b - sqrt(det)) / (2 * a);
154 solution[1] = (-b + sqrt(det)) / (2 * a);
double ipow(const double x, const int64_t p)
Compute x raised to the power p (x^p).
double poly(double *a, long n, double x)
Evaluate a polynomial at a given point.
double dpoly(double *a, long n, double x)
Evaluate the derivative of a polynomial at a given point.
double dpolyp(double *a, long *power, long n, double x)
Evaluate the derivative of a polynomial with arbitrary powers at a given point.
double polyp(double *a, long *power, long n, double x)
Evaluate a polynomial with arbitrary powers at a given point.
int solveQuadratic(double a, double b, double c, double *solution)
Solve a quadratic equation for real solutions.