The usual way of calculating x mod 8 is to use operator%. This involves a division operation, which is intrinsically slow. A better way to calculate this is to use operator& (x & 7). Even this is slower than it needs to be. For a multiple precision integer, only the least significant digit needs to be considered.
The default implementation of this method uses x mod 8, since not all multiple precision libraries implement operator&. The optimization mentioned above should be implemented in a specialization for type T, if applicable.
Name | Type | Description |
---|---|---|
x | T | Some number. |
#include <nttl/nttlTraits.h> ... nttlTraits<int> tr; ... int x = 123; int a = tr.Mod8( x ); |