История изменений
Исправление beastie, (текущая версия) :
Таки общего мнения нет. https://torstencurdt.com/tech/posts/modulo-of-negative-numbers/
mod
vs. rem
каждый интерпретирует, как может.
TL;DR:
Language | 13 mod 3 | -13 mod 3 | 13 mod -3 | -13 mod -3 |
---|---|---|---|---|
C | 1 | -1 | 1 | -1 |
C# | 1 | -1 | 1 | -1 |
C++ | 1 | -1 | 1 | -1 |
Elixir | 1 | -1 | 1 | -1 |
Erlang | 1 | -1 | 1 | -1 |
Go | 1 | -1 | 1 | -1 |
Java | 1 | -1 | 1 | -1 |
Javascript | 1 | -1 | 1 | -1 |
Kotlin | 1 | -1 | 1 | -1 |
Nim | 1 | -1 | 1 | -1 |
PHP | 1 | -1 | 1 | -1 |
Rust | 1 | -1 | 1 | -1 |
Scala | 1 | -1 | 1 | -1 |
Swift | 1 | -1 | 1 | -1 |
Crystal | 1 | 2 | -2 | -1 |
Haskell | 1 | 2 | -2 | -1 |
Lua | 1 | 2 | -2 | -1 |
Python | 1 | 2 | -2 | -1 |
Ruby | 1 | 2 | -2 | -1 |
Dart | 1 | 2 | 1 | 2 |
Zig | 1 | -1 | error | error |
Zig | 1 | 2 | error | error |
Исправление beastie, :
Таки общего мнения нет. https://torstencurdt.com/tech/posts/modulo-of-negative-numbers/
TL;DR:
Language | 13 mod 3 | -13 mod 3 | 13 mod -3 | -13 mod -3 |
---|---|---|---|---|
C | 1 | -1 | 1 | -1 |
C# | 1 | -1 | 1 | -1 |
C++ | 1 | -1 | 1 | -1 |
Elixir | 1 | -1 | 1 | -1 |
Erlang | 1 | -1 | 1 | -1 |
Go | 1 | -1 | 1 | -1 |
Java | 1 | -1 | 1 | -1 |
Javascript | 1 | -1 | 1 | -1 |
Kotlin | 1 | -1 | 1 | -1 |
Nim | 1 | -1 | 1 | -1 |
PHP | 1 | -1 | 1 | -1 |
Rust | 1 | -1 | 1 | -1 |
Scala | 1 | -1 | 1 | -1 |
Swift | 1 | -1 | 1 | -1 |
Crystal | 1 | 2 | -2 | -1 |
Haskell | 1 | 2 | -2 | -1 |
Lua | 1 | 2 | -2 | -1 |
Python | 1 | 2 | -2 | -1 |
Ruby | 1 | 2 | -2 | -1 |
Dart | 1 | 2 | 1 | 2 |
Zig | 1 | -1 | error | error |
Zig | 1 | 2 | error | error |
Исходная версия beastie, :