public static int solveQuad ( double [ ] eqn , double [ ] res ) { double a = eqn [ 2 ] ; double b = eqn [ 1 ] ; double c = eqn [ 0 ] ; int rc = 0 ; if ( a == 0f ) { if ( b == 0f ) { return - 1 ; } res [ rc ++ ] = - c / b ; } else { double d = b * b - 4f * a * c ; // d < 0f if ( d < 0f ) { return 0 ; } d = Math . sqrt ( d ) ; res [ rc ++ ] = ( - b + d ) / ( a * 2f ) ; // d != 0f if ( d != 0f ) { res [ rc ++ ] = ( - b - d ) / ( a * 2f ) ; } } return fixRoots ( res , rc ) ; }
Solves quadratic equation