Faster remainders when the divisor is a constant: beating compilers and libdivide
Daniel Lemire
FEBRUARY 8, 2019
The division by a power of two ( / (2 N )) can be implemented as a right shift if we are working with unsigned integers, which compiles to single instruction: that is possible because the underlying hardware uses a base 2. uint64_t c = UINT64_C ( 0xFFFFFFFFFFFFFFFF ) / d + 1 ; // fastmod computes (n mod d) given precomputed c.
Let's personalize your content