diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-11-01 02:49:52 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-11-01 02:49:52 -0400 |
commit | 5226e19e3bf2e082b02dec9e856e2613744c8571 (patch) | |
tree | 1174814d83ab5ddd1b6fed8f227220693ad4c52e | |
parent | 80388b952b5844261e711e8da5a59c34b4919da7 (diff) | |
download | dimension-5226e19e3bf2e082b02dec9e856e2613744c8571.tar.xz |
More numerical tweaks.
-rw-r--r-- | libdimension/dimension/geometry.h | 2 | ||||
-rw-r--r-- | libdimension/polynomial.c | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/libdimension/dimension/geometry.h b/libdimension/dimension/geometry.h index 4c4f8b8..6ff9941 100644 --- a/libdimension/dimension/geometry.h +++ b/libdimension/dimension/geometry.h @@ -63,7 +63,7 @@ typedef struct dmnsn_bounding_box { dmnsn_vector min, max; } dmnsn_bounding_box; /* Constants */ -#define dmnsn_epsilon 1.0e-9 +#define dmnsn_epsilon 1.0e-10 static const dmnsn_vector dmnsn_zero = { 0.0, 0.0, 0.0 }; static const dmnsn_vector dmnsn_x = { 1.0, 0.0, 0.0 }; diff --git a/libdimension/polynomial.c b/libdimension/polynomial.c index 6e2aed2..ab80f69 100644 --- a/libdimension/polynomial.c +++ b/libdimension/polynomial.c @@ -57,6 +57,15 @@ dmnsn_real_degree(const double poly[], size_t degree) return 0; } +/* Divide each coefficient by the leading coefficient */ +static inline void +dmnsn_normalize_polynomial(double poly[], size_t degree) +{ + for (size_t i = 0; i <= degree; ++i) { + poly[i] /= poly[degree]; + } +} + /* Eliminate trivial zero roots from poly[] */ static inline void dmnsn_eliminate_zero_roots(double poly[], size_t *degree) @@ -285,6 +294,8 @@ dmnsn_solve_polynomial(const double poly[], size_t degree, double x[]) /* Account for leading zero coefficients */ degree = dmnsn_real_degree(p, degree); + /* Normalize the leading coefficient to 1.0 */ + dmnsn_normalize_polynomial(p, degree); /* Eliminate simple zero roots */ dmnsn_eliminate_zero_roots(p, °ree); |