From 665d154c9522ce662ca15d54c1e64f9167e6cd76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ju=CC=88rg=20Lehni?= Date: Sat, 10 Jan 2015 17:57:37 +0100 Subject: [PATCH] Simplify control-flow in Numerical.solveCubic() a bit. --- src/util/Numerical.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/util/Numerical.js b/src/util/Numerical.js index b4d839d4..50f9bb66 100644 --- a/src/util/Numerical.js +++ b/src/util/Numerical.js @@ -265,19 +265,17 @@ var Numerical = new function() { */ solveCubic: function(a, b, c, d, roots, min, max) { var x, b1, c2, nRoots = 0; - if (a === 0 || d ===0) { - // We only need to solve a quadratic. - // So we set the coefficients appropriately. - if (a === 0) { - a = b; - b1 = c; - c2 = d; - x = Infinity; - } else { - b1 = b; - c2 = c; - x = 0; - } + // If a or d is zero, we only need to solve a quadratic, so we set + // the coefficients appropriately. + if (a === 0) { + a = b; + b1 = c; + c2 = d; + x = Infinity; + } else if (d === 0) { + b1 = b; + c2 = c; + x = 0; } else { var ec = 1 + MACHINE_EPSILON, // 1.000...002 x0, q, qd, t, r, s, tmp;