From: "Mike T. Miller" Date: 2001-05-08T04:40:48+09:00 Subject: [ruby-talk:14802] Re: Integer division oddness In partial answer to my own post, I just found this link: http://xenia.media.mit.edu/~bdenckla/thesis/texts/htthe/node13.html It still seems wrong to me. Which is right? -1 or -2? I guess it boils down to whether or not you believe that the modulus can be negative. " My father pointed out this oddity. " " Using integer math, try this on various languages: " " -10 / 9 " " For ruby, python and tcl you get: -2! " For java, c and gforth you get: -1 " " Getting -2 seems really wrong to me. I looked at the " code for ruby and found this: (numeric.c: line 1056) " " if ((mod < 0 && y > 0) || (mod > 0 && y < 0)) { " mod += y; " div -= 1; " } " " So, bascially, one is subtracted on purpose in this case. " Is this an accepted way to do integer division tha I'm not " familiar with? " " thanks, " Mike