From bb438b6252a850b3091e9e5b86563dcf2d966596 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Wed, 10 Dec 2014 13:24:53 +0000 Subject: [PATCH] math: fix a coding error in the polynomial division. --- src/lol/math/polynomial.h | 2 +- src/t/math/polynomial.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lol/math/polynomial.h b/src/lol/math/polynomial.h index 162185cb..ad062209 100644 --- a/src/lol/math/polynomial.h +++ b/src/lol/math/polynomial.h @@ -286,9 +286,9 @@ struct polynomial for (int n = remainder.degree() - p.degree(); n >= 0; --n) { quotient.set(n, remainder.leading()); - remainder.m_coefficients.Pop(); for (int i = 0; i < p.degree(); ++i) remainder.m_coefficients[n + i] -= remainder.leading() * p[i]; + remainder.m_coefficients.Pop(); } return ret; diff --git a/src/t/math/polynomial.cpp b/src/t/math/polynomial.cpp index 706d406f..9651eefa 100644 --- a/src/t/math/polynomial.cpp +++ b/src/t/math/polynomial.cpp @@ -190,6 +190,9 @@ lolunit_declare_fixture(PolynomialTest) polynomial p { -4.f, 0.f, -2.f, 1.f }; polynomial q { -3.f, 1.f }; + /* p(x) = r(x) q(x) + s(x) + * r(x) = 3 + x + x² + * s(x) = 5 */ auto r = p / q; lolunit_assert_equal(r.m1.degree(), 2); lolunit_assert_doubles_equal(r.m1[0], 3.f, 1e-5f);