I'm trying to find possible integer roots of a quadratic equation with Java.
Here is a snippet from my code:
double sqrtDiscriminant = Math.sqrt(b * b - 4 * a * c);
double root1 = ((-1.0 * b) - sqrtDiscriminant) / (2.0 * a);
double root2 = ((-1.0 * b) + sqrtDiscriminant) / (2.0 * a);
For a = 2
, b = -1
and c = -40755
, one of the roots is 143.0
(143.0
is printed to console when I echo it so I'm only interested in such
double values, not 143.00001
)
My question is, how can I make sure that any root has an integer value?
If root1 = 143.0
then e.g. root1 == 143
should return true.
I tried root1 == Math.floor(root1)
but it didn't work.