From 59188cfffeb093c482836df391e6c05d7ab3081c Mon Sep 17 00:00:00 2001 From: Hanlin Dong Date: Mon, 6 Feb 2023 14:14:59 +0800 Subject: [PATCH] Bug fix on discrim<0 case. -term1 was added to a wrong place. Corrected. --- cubic.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cubic.js b/cubic.js index b37c837..ed5840a 100644 --- a/cubic.js +++ b/cubic.js @@ -58,11 +58,11 @@ const cubicSolve = (a, b, c, d) => { // Only option left is that all roots are real and unequal (to get here, q < 0) else { const dum1 = Math.acos(r / Math.sqrt(-q * -q * -q)) - const temp = -term1 + 2.0 * Math.sqrt(-q) + const temp = 2.0 * Math.sqrt(-q) - roots[0].real = temp * Math.cos(dum1 / 3.0) - roots[1].real = temp * Math.cos((dum1 + 2.0 * Math.PI) / 3.0) - roots[2].real = temp * Math.cos((dum1 + 4.0 * Math.PI) / 3.0) + roots[0].real = -term1 + temp * Math.cos(dum1 / 3.0) + roots[1].real = -term1 + temp * Math.cos((dum1 + 2.0 * Math.PI) / 3.0) + roots[2].real = -term1 + temp * Math.cos((dum1 + 4.0 * Math.PI) / 3.0) return roots }