Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Why Python's Integer Division Floors (python-history.blogspot.com)
7 points by mgrouchy on Aug 24, 2010 | hide | past | favorite | 2 comments


Cool. So many languages get it wrong it doesn't even occur to me to check any more when learning a new language. I just assume that a mod b, where b is positive, can produce a value less than 0, and normalize the result to [0, b).


"So why doesn't C do it this way? Probably the hardware didn't do this at the time C was designed."

As far as I know, hardware still doesn't do this, if we look at the assembly instructions of CPU's. The languages that specify it towards zero have the advantage of being able to map the computation to the single CPU instruction.




Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: