Is there a c++ function (built-in or otherwise) that gives the integer division and modular division results without repeating the operation?
-
30-10-2019 - |
Pergunta
You could write something like:
int i = 3;
int k = 2;
int division = i / k;
int remainder = i % k;
It seems as thought this would, on a low level, ask an ALU to perform two vision operations: one returning the quotient, and one returning the remainder. However, I believe an ALU would most likely calculate both in a single operation. If that is the case, this is not optimally efficient.
Is there a more efficient way of doing it, without asking the CPU to calculate twice? In other words, can it be done in a single operation from C++?
Nenhuma solução correta
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow