2 ms·
With many compilers (e.g. clang, msvc) this will emit actual division without optimization (and if the number is signed it's quite a lot of code). If such code
by pandaman 9y ago
With many compilers (e.g. clang, msvc) this will emit actual division without optimization (and if the number is signed it's quite a lot of code). If such code is in the inner loops it can hit performance, which is already not great without the compiler's optimization. And if one ever looked for a bug that takes more than few seconds to reproduce then the debug build's performance cannot be over-valued.
Though if this is a hack then checking the last digit to see if a decimal number is even is also a hack :)
- slx26 9y agoWhich brings us to: knowing when to use bit hacks is as important as knowing how to implement them. And you usually want to know about compilers for that.