I am trying to write a program to solve a quadratic equation whose coefficients\' values do not exceed 100 by absolute value and it is guaranteed that if any roots exist, they a
The root cause here (pun very much accepted) is that the quadratic equation is not a Diophantine equation. It applies to real numbers, and in particular sqrt(d)
is usually not an integer.
In C++, the return type of sqrt(IntegralType)
is double
. Thus 2*a
is converted to double
too, but only after multiplying. And Visual Studio very reasonably notes that you're better off doing the conversion before multiplying. It just doesn't note that you can even make a,b,c
all doubles from the start.