public static int solveQuad(double a, double b, double c, double [] roots) { // System.err.println("Quad: " + a +"t^2 + " + b +"t + " + c); if (a == 0) { // no square term. return solveLine(b, c, roots); } double det = b*b-4*a*c; // System.err.println("Det: " + det); if (Math.abs(det) <= tol*b*b) { // one real root (det doesn't contain any useful info) roots[0] = -b/(2*a); return 1; } if (det < 0) return 0; // No real roots // Two real roots det = Math.sqrt(det); double w = -(b + matchSign(det, b)); roots[0] = (2*c)/w; roots[1] = w/(2*a); return 2; }
public static int solveQuad(double a, double b, double c, double [] roots) { // System.err.println("Quad: " + a +"t^2 + " + b +"t + " + c); if (a == 0) { // no square term. return solveLine(b, c, roots); } double det = b*b-4*a*c; // System.err.println("Det: " + det); if (Math.abs(det) <= tol*b*b) { // one real root (det doesn't contain any useful info) roots[0] = -b/(2*a); return 1; } if (det < 0) return 0; // No real roots // Two real roots det = Math.sqrt(det); double w = -(b + matchSign(det, b)); roots[0] = (2*c)/w; roots[1] = w/(2*a); return 2; }
public static int solveQuad(double a, double b, double c, double [] roots) { // System.err.println("Quad: " + a +"t^2 + " + b +"t + " + c); if (a == 0) { // no square term. return solveLine(b, c, roots); } double det = b*b-4*a*c; // System.err.println("Det: " + det); if (Math.abs(det) <= tol*b*b) { // one real root (det doesn't contain any useful info) roots[0] = -b/(2*a); return 1; } if (det < 0) return 0; // No real roots // Two real roots det = Math.sqrt(det); double w = -(b + matchSign(det, b)); roots[0] = (2*c)/w; roots[1] = w/(2*a); return 2; }