From ddf9354b67f0df778cea60a91c57f9404731acf5 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 19 May 2015 12:23:51 +0000 Subject: [PATCH] math: simplify some computations in the degree-3 root finder. --- src/lol/math/polynomial.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lol/math/polynomial.h b/src/lol/math/polynomial.h index bf66867d..3ff2a43a 100644 --- a/src/lol/math/polynomial.h +++ b/src/lol/math/polynomial.h @@ -160,9 +160,9 @@ struct polynomial T const &d = m_coefficients[0]; /* Using x = (X - k) so that p2(X) = p(X - k) = aX³ + 0×X² + mX + n */ - T const k = b / (3 * a); - T const m = 3 * a * k * k - 2 * b * k + c; - T const n = -a * k * k * k + b * k * k - c * k + d; + T const k = b / (T(3) * a); + T const m = c - b * k; + T const n = (T(2) / T(3) * b * k - c) * k + d; /* Assuming X = u + v and 3uv = -m, then * p2(u + v) = a(u + v) + n