From: Dave Thomas Date: 2002-02-05T08:30:03+09:00 Subject: Re: Division Modulo Problem "f. bou" writes: > Sorry a little failure. > I got some nice division and module problems with Ruby 1.6.6: > 9 / 2 = 4 > -9 / 2 = -5 ??? > 9 / -2 = -5 ??? > 9 % 2 = 1 > -9 % 2 = 1 ??? > 9 % -2 = -1 ??? Have you looked at the descriptions of class Numeric: http://www.rubycentral.com/book/ref_c_numeric.html (sorry about the table - it looks better in the printed book). The relevant equation is q,r = x.divmod(y) where q = floor(float(x)/float(y)) r = x - q*y Modulo always returns a number with the same sign as the divisor, whereas remainder has the sign of the dividend. Regards Dave