3 ms·
At least that’s the reason I’ve heard for preferring C-style mod. Or rather, round-to-zero integer division it faster than round-to-negative-infinity integer di
by Skeime 4y ago
At least that’s the reason I’ve heard for preferring C-style mod. Or rather, round-to-zero integer division it faster than round-to-negative-infinity integer division and arguably, you should choose / and % such that a = (a / b) * b + (a % b) always holds. This then forces the strange convention for %.
- LegionMammal978 4y ago> round-to-zero integer division it faster than round-to-negative-infinity integer division Do you have a source for this? Obviously, the big instruction sets natively implement round-to-zero division because that's what everyone already uses, but I've always attributed that to historical accident rather than first principles.
- Aardwolf 4y agoI'd even argue that flooring division is also more useful than round to zero and is also what binary shifting does. At least more useful for my use-cases (things like dealing with coordinates in game worlds, ...), but unlike for modulo, at least here I can imagine use cases where the other option, round to zero, is also useful (e.g. financial, ...)