bool is_multiple_of_3(unsigned x) { unsigned y; do { y = 0; while (x) { y += x & 3; x >>= 2; } x = y; } while (y > 5); return y == 3; }
-
-
Replying to @ch3root1 reply 2 retweets 3 likes
-
Replying to @RichFelker
@solardiz@ch3root For non-constant n, you can also precompute the parameters and do it yourself. See http://ridiculousfish.com/blog/posts/labor-of-division-episode-iii.html …1 reply 1 retweet 2 likes -
Replying to @RichFelker
@solardiz@ch3root The parametrized ver reduces to: return x - ((unsigned long)(1ULL * (x>>s1) * mul + add >> (64-8*sizeof 0L)) >> s2)*div;1 reply 0 retweets 0 likes
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.