在 C++ 中,模数是否在幕后使用任何 float 学?
int x = 1234;
int y = 5678;
int z = y % x; // any floating point used underneath to calculate the integer result?
作为背景,我在想this question他说他不能在没有 FP 仿真的情况下使用任何 float 。然后我意识到我不确定模数运算符是否使用了任何类型的浮点汇编操作。我的猜测是不会,但我想确定一下。
最佳答案
没有1。请引用此类运算符的一些实现。
Assembly Language - How to Do Modulo? - “[在 x86 中] DIV 指令 [..] 给出商和余数”
Assembly mod algorithm on processor with no division operator
1 实现 可以做任何它想做的事情,只要观察到的行为在规范范围内。但是,我不知道有任何实现会选择使用浮点运算,我也想不出这样做的一般理由。
关于c++ - 模数是否在幕后使用 float ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21614893/