Talk:Detect division by zero

From Rosetta Code
Revision as of 15:58, 18 June 2010 by rosettacode>Richie Cotton (Discussed problem with 0 / 0)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Many of the solutions here simply check that the result is infinite. This will fail if the numerator is 0 too, since 0 / 0 is mathematically incalculable (many languages return NaN here).

A correct pseudocode solution is:

result = numerator / denominator
if numerator equals 0
   if result is not a number
      divide by zero action
   end
else 
   if result is infinite
      divide by zero action
   end
end