问题描述
显然,x86(可能还有很多其他指令集)将除法运算的商和余数都放在单独的寄存器中.
Apparently, x86 (and probably a lot of other instruction sets) put both the quotient and the remainder of a divide operation in separate registers.
现在,我们可能可以信任编译器来优化这样的代码,使其仅使用一个调用来进行除法:
Now, we can probably trust compilers to optimize a code such as this to use only one call to divide:
( x / 6 )
( x % 6 )
他们可能会这么做.但是,是否有任何语言(或库,但主要是在寻找语言)支持同时给出除法和取模结果?如果是这样,它们是什么,语法是什么样的?
And they probably do. Still, do any languages (or libraries, but mainly looking for languages) support giving both the divide and modulo results at the same time? If so, what are they, and What does the syntax look like?
推荐答案
C具有 div
和ldiv
.它们是否为商和余数生成单独的指令,将取决于您特定的标准库实现以及编译器和优化设置.从C99开始,您还具有lldiv
表示较大的数字.
C has div
and ldiv
. Whether these generate separate instructions for the quotient and remainder will depend on your particular standard library implementation and compiler and optimization settings. Starting with C99, you also have lldiv
for larger numbers.
这篇关于同时划分和获取余数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!