Simplify control-flow in Numerical.solveCubic() a bit.

This commit is contained in:
Jürg Lehni 2015-01-10 17:57:37 +01:00
parent 814512f562
commit 665d154c95

View file

@ -265,19 +265,17 @@ var Numerical = new function() {
*/ */
solveCubic: function(a, b, c, d, roots, min, max) { solveCubic: function(a, b, c, d, roots, min, max) {
var x, b1, c2, nRoots = 0; var x, b1, c2, nRoots = 0;
if (a === 0 || d ===0) { // If a or d is zero, we only need to solve a quadratic, so we set
// We only need to solve a quadratic. // the coefficients appropriately.
// So we set the coefficients appropriately. if (a === 0) {
if (a === 0) { a = b;
a = b; b1 = c;
b1 = c; c2 = d;
c2 = d; x = Infinity;
x = Infinity; } else if (d === 0) {
} else { b1 = b;
b1 = b; c2 = c;
c2 = c; x = 0;
x = 0;
}
} else { } else {
var ec = 1 + MACHINE_EPSILON, // 1.000...002 var ec = 1 + MACHINE_EPSILON, // 1.000...002
x0, q, qd, t, r, s, tmp; x0, q, qd, t, r, s, tmp;