Why is -7 mod 3 = 2 in Ruby?
math, ruby
Solution
Because -7 minus 2 is a multiple of 3.
More specifically, the implementation of modulus used in that case happens to choose the positive modulus. Some implementations choose the modulus with the same sign as the first operand, others always choose positive, etc.
Problem
I am coming from Java to Ruby and this -7 mod 3 = 2 puzzles me