Is it possible to get division by 0 (or infinity) in the following example?
public double calculation(double a, double
Division by zero is undefined, since the limit from positive numbers tend to infinity, the limited from negative numbers tend to negative infinity.
Not sure if this is C++ or Java since there is no language tag.
double calculation(double a, double b)
{
if (a == b)
{
return nan(""); // C++
return Double.NaN; // Java
}
else
{
return 2 / (a - b);
}
}