Why does the Rem operator in Elixir return negative numbers?
3 answers
The remainder sign actually changes for every programming language: https://en.wikipedia.org/wiki/Modulo_operation . So both are correct and both are wrong. :)
+7
source to share
In the words of Davis Thomas in Elixir Programming:
rem is the remainder operator. It is called a function (rem (11, 3) => 2). This differs from the usual modulo operations in that the result will have the same sign as the first argument of the functions.
This means that in your case, which is rem (-1, 25), the result will have a - sign, just like the first arg.
+3
source to share