Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yes, for constant divisors.

However, for signed division, the C semantics (round towards zero) are different than the semantics when you apply an arithmetic shift (round towards negative infinity).

If you are fine with the latter behavior explicit shifts remove several extraneous instructions dealing with the difference.



Or you can do the division in unsigned types - reasonable for something like an array index.




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

Search: