As other people have said, div() will provide you with the private and the rest. This is because the integer (software) is a separation algorithm that in most cases uses C as at the same time.
If the target computer does not have a hardware splitter, the / operator usually turns into a div() call, and the remainder is discarded. The same thing happens with % operator, except that he receives a throw. So if you are something like this:
quot = a / b; rem = a % b;
you call the division procedure twice (and division is rather slow if your computer does not do this in hardware). So it's faster to use div() to get both.
(Of course, this is also less readable and whether you really gain performance depends on your specific platform and compiler. You should only switch to div() if you determine that this is a performance bottleneck. Remember what Knut said about premature optimization) .
Chris Reuter Jul 30 '12 at 17:13 2012-07-30 17:13
source share