To check if something is a real number, use isnan
:
if(!isnan(root1) && !isnan(root2))
Explanation:
isnan
determines if the given floating point number arg is not-a-number (NaN). It returns true
if arg is NaN, false
otherwise.
The NaN values are used to identify undefined or non-representable values for floating-point elements, such as the square root of negative numbers or the result of 0/0. In C++, it is implemented with function overloads for each floating-point type, each returning a bool value.