top | item 27730577

(no title)

Rompect | 4 years ago

This is like the easiest thing for a compiler to detect and optimize.

discuss

order

codeflo|4 years ago

True, but something to be aware of: If the compiler uses bitwise operations to implement %, it emits special handling of negative values (it's really more of a remainder operator than a modulus). You can avoid that either by using unsigned numbers, or & as suggested:

https://godbolt.org/z/vdz59q994