function computeRealRoots(a, b, c, d) {
  const A = a;
  const B = b / 3.0;
  const C = c / 3.0;
  const D = d;

  const AC = A * C;
  const BD = B * D;
  const B2 = B * B;
  const C2 = C * C;
  const delta1 = A * C - B2;
  const delta2 = A * D - B * C;
  const delta3 = B * D - C2;

  const discriminant = 4.0 * delta1 * delta3 - delta2 * delta2;
  let temp;
  let temp1;

  if (discriminant < 0.0) {
    let ABar;
    let CBar;
    let DBar;

    if (B2 * BD >= AC * C2) {
      ABar = A;
      CBar = delta1;
      DBar = -2.0 * B * delta1 + A * delta2;
    } else {
      ABar = D;
      CBar = delta3;
      DBar = -D * delta2 + 2.0 * C * delta3;
    }

    const s = DBar < 0.0 ? -1.0 : 1.0; // This is not Math.Sign()!
    const temp0 = -s * Math.abs(ABar) * Math.sqrt(-discriminant);
    temp1 = -DBar + temp0;

    const x = temp1 / 2.0;
    const p = x < 0.0 ? -Math.pow(-x, 1.0 / 3.0) : Math.pow(x, 1.0 / 3.0);
    const q = temp1 === temp0 ? -p : -CBar / p;

    temp = CBar <= 0.0 ? p + q : -DBar / (p * p + q * q + CBar);

    if (B2 * BD >= AC * C2) {
      return [(temp - B) / A];
    }

    return [-D / (temp + C)];
  }

  const CBarA = delta1;
  const DBarA = -2.0 * B * delta1 + A * delta2;

  const CBarD = delta3;
  const DBarD = -D * delta2 + 2.0 * C * delta3;

  const squareRootOfDiscriminant = Math.sqrt(discriminant);
  const halfSquareRootOf3 = Math.sqrt(3.0) / 2.0;

  let theta = Math.abs(Math.atan2(A * squareRootOfDiscriminant, -DBarA) / 3.0);
  temp = 2.0 * Math.sqrt(-CBarA);
  let cosine = Math.cos(theta);
  temp1 = temp * cosine;
  let temp3 = temp * (-cosine / 2.0 - halfSquareRootOf3 * Math.sin(theta));

  const numeratorLarge = temp1 + temp3 > 2.0 * B ? temp1 - B : temp3 - B;
  const denominatorLarge = A;

  const root1 = numeratorLarge / denominatorLarge;

  theta = Math.abs(Math.atan2(D * squareRootOfDiscriminant, -DBarD) / 3.0);
  temp = 2.0 * Math.sqrt(-CBarD);
  cosine = Math.cos(theta);
  temp1 = temp * cosine;
  temp3 = temp * (-cosine / 2.0 - halfSquareRootOf3 * Math.sin(theta));

  const numeratorSmall = -D;
  const denominatorSmall = temp1 + temp3 < 2.0 * C ? temp1 + C : temp3 + C;

  const root3 = numeratorSmall / denominatorSmall;

  const E = denominatorLarge * denominatorSmall;
  const F =
    -numeratorLarge * denominatorSmall - denominatorLarge * numeratorSmall;
  const G = numeratorLarge * numeratorSmall;

  const root2 = (C * F - B * G) / (-B * F + C * E);

  if (root1 <= root2) {
    if (root1 <= root3) {
      if (root2 <= root3) {
        return [root1, root2, root3];
      }
      return [root1, root3, root2];
    }
    return [root3, root1, root2];
  }
  if (root1 <= root3) {
    return [root2, root1, root3];
  }
  if (root2 <= root3) {
    return [root2, root3, root1];
  }
  return [root3, root2, root1];
}
Provides the discriminant of the cubic equation from the supplied coefficients.

@param {number} a The coefficient of the 3rd order monomial.
@param {number} b The coefficient of the 2nd order monomial.
@param {number} c The coefficient of the 1st order monomial.
@param {number} d The coefficient of the 0th order monomial.
@returns {number} The value of the discriminant.