diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-11-18 18:48:22 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-11-18 18:48:22 -0500 |
commit | 17e517be54922a848a4e79394d0969d57e5b3b9e (patch) | |
tree | 3b80b4a02bdb5209c7f9023011a90189d350f3af /libdimension | |
parent | a69a062b31a26f04699315179ed1026d9cfedf5e (diff) | |
download | dimension-17e517be54922a848a4e79394d0969d57e5b3b9e.tar.xz |
A couple polynomial.c improvements.
Diffstat (limited to 'libdimension')
-rw-r--r-- | libdimension/polynomial.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/libdimension/polynomial.c b/libdimension/polynomial.c index 09a2bb0..0c4168d 100644 --- a/libdimension/polynomial.c +++ b/libdimension/polynomial.c @@ -69,17 +69,9 @@ dmnsn_eliminate_zero_roots(double poly[], size_t *degree) static inline size_t dmnsn_descartes_rule(const double poly[], size_t degree) { - int lastsign = 0; - size_t i; - for (i = 0; i <= degree; ++i) { - if (fabs(poly[i]) >= dmnsn_epsilon) { - lastsign = dmnsn_signbit(poly[i]); - break; - } - } - size_t changes = 0; - for (++i; i <= degree; ++i) { + int lastsign = dmnsn_signbit(poly[degree]); + for (size_t i = degree; i-- > 0;) { int sign = dmnsn_signbit(poly[i]); if (fabs(poly[i]) >= dmnsn_epsilon && sign != lastsign) { lastsign = sign; @@ -209,15 +201,15 @@ dmnsn_uspensky_bounds(const double poly[], size_t degree, double bounds[][2], } } -/** Calculate a finite upper bound for the roots of \p poly[]. */ +/** Calculate a finite upper bound for the roots of the normalized polynomial + \p poly[]. */ static inline double -dmnsn_root_bound(double poly[], size_t degree) +dmnsn_root_bound(const double poly[], size_t degree) { double bound = 0.0; for (size_t i = 0; i < degree; ++i) { bound = dmnsn_max(bound, fabs(poly[i])); } - bound /= fabs(poly[degree]); bound += 1.0; return bound; } |