Bugzilla – Bug 14754
integer divide by zero gives wrong answer
Last modified: 2011-12-15 11:09:04 UTC
> 1 %/% 0
> 1L %/% 0L
According to ?'%/%', the results should be NA-ish:
unless y == 0 where the result is NA_integer_ or NaN (depending on the typeof() of the arguments)
I could see a rationale for Inf with reals (so you could change the doco instead), but for 1L %/% 0L only NA makes sense since Inf_integer_ doesn't exist.
The remainder versions '%%' work as expected.
The bug happens on
and also on R 2.13.2-- haven't checked 2.14.
This is a matter of convention: we will examine conventions elsewhere.
The consensus seems to be that the result is undefined. In which case there is no 'wrong answer', but NA_integer_ seems a better idea than 0.
Changed in R-devel (but not for 2.14.1).