Is it possible to get division by 0 (or infinity) in the following example?
public double calculation(double a, double
Based on @malarres response and @Taemyr comment, here is my little contribution:
public double calculation(double a, double b)
{
double c = 2 / (a - b);
// Should not have a big cost.
if (isnan(c) || isinf(c))
{
return 0; // A 'whatever' value.
}
else
{
return c;
}
}
My point is to says: the easyest way to know if the result of the division is nan or inf is actualy to perform the division.