Bug 14754 - integer divide by zero gives wrong answer
integer divide by zero gives wrong answer
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Accuracy
R 2.13.2
ix86 (32-bit) Windows 32-bit
: P5 trivial
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-12-12 23:44 UTC by Mark Bravington
Modified: 2011-12-15 11:09 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Bravington 2011-12-12 23:44:09 UTC
> 1 %/% 0
[1] Inf

> 1L %/% 0L
[1] 0

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

> getRversion()
[1] ‘2.15.0’

and also on R 2.13.2-- haven't checked 2.14.
Comment 1 Brian Ripley 2011-12-14 22:47:43 UTC
This is a matter of convention: we will examine conventions elsewhere.
Comment 2 Brian Ripley 2011-12-15 11:09:04 UTC
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).