I am coming from Java to Ruby and this -7 mod 3 = 2 puzzles me
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.