R consistent integer division and modulo operation#250
Merged
MichaelChirico merged 3 commits intomainfrom Jan 25, 2026
Merged
Conversation
|
|
||
| 1. `as.integer64.integer64` returns a plain `integer64` vector stripped of any attributes. This is consistent with R like behavior, e.g. `as.integer.integer`. | ||
|
|
||
| 1. `%/%` does not truncate towards zero any more. It now matches R behavior of truncating towards negative infinity. For example, `as.integer64(-10L) %/% as.integer64(7L)` now gives `-2L`, not `-1L`. This is consistent with `-10L %/% 7L` in base R. Consequently, `%%` is also affected, e.g. `as.integer64(-10L) %% as.integer64(7L)` now gives `4L`, not `-3L`, consistent with `-10L %% 7L` in base R. |
Collaborator
There was a problem hiding this comment.
In ?"%/%" this is described as Knuth's floor() behavior:
x %/% y := floor(x / y)
I think it will be helpful to use that terminology to anchor more definitively to the base rule.
MichaelChirico
approved these changes
Jan 25, 2026
Collaborator
MichaelChirico
left a comment
There was a problem hiding this comment.
Since the previous behavior is IMO incorrect, I think of this more as a bug, hence less concerned about back-compatibility.
Still, I'll keep an eye on it aroud release time when doing reverse dependency checks -- if it is a recurring source of downstream breaking, we may guard this with a flag, too.
hcirellu
added a commit
that referenced
this pull request
Jan 26, 2026
* r consistent integer division * tweak NEWS --------- Co-authored-by: Michael Chirico <chiricom@google.com>
MichaelChirico
added a commit
that referenced
this pull request
Mar 13, 2026
* extend c, cbind, and rbind * consistent use of Rboolean (#251) * R consistent integer division and modulo operation (#250) * r consistent integer division * tweak NEWS --------- Co-authored-by: Michael Chirico <chiricom@google.com> * fix test ancient * add origin for as.{Date,POSIXct,POSIXlt} for ancient * `stringsAsFactors=FALSE` for ancient * fix ancient * skip a test for ancient * fix cbind tests for ancient * skip cbind tests for ancient * skip rbind tests for ancient * fix target_class_and_sample_value for missing .bit64.suppressPromoteInteger64ToCharacterMessage * merge target_class_and_sample_value in target_class * touch-ups to c() * touch-ups to rbind,cbind * missing ')' * inherits() instead of class() Co-authored-by: Michael Chirico <chiricom@google.com> * remove eval(str2lang()) * another round of touch-up * vestigial ')' * missing '{' * simplify (?) replacement helper for cbind * more expect_same_error * switch branch order * fix updated logical condition for unnested branches * revert unrelated switch to expect_same_error * replace rbind helper too * fix helper argument name Co-authored-by: Michael Chirico <michaelchirico4@gmail.com> * refactoring, add comments, add news * extract replace_dimnames * tweak NEWS * fix deparse.level problems * skip ancient test * more canonical patrick (avoid expand.grid), don't test 4 * raw cases * missing symmetric cases for difftime, factor, ordered * explicitly ignore coercion warning before error --------- Co-authored-by: Michael Chirico <chiricom@google.com> Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The integer division is changed to meet the behavior of base R for integer. I couldn't find any "option" to change the behaviour for
long long int, so I added logic.Closes #248