我想要标准 (n3242/3291/3290) 中关于定义余数运算符不适用于浮点类型的位置的指针。
余数运算符%
定义在5.6.2
The binary / operator yields the quotient, and the binary % operator yields the remainder from the division of the first expression by the second. If the second operand of / or % is zero the behavior is undefined. For integral operands the / operator yields the algebraic quotient with any fractional part discarded if the quotient a/b is representable in the type of the result, (a/b)*b + a%b is equal to a.
我找不到禁止使用浮点类型的地方。事实上,标准明确地将 integral operands
视为一种特殊情况,可以解释为:该运算符存在于其他非整数类型。
我知道 MSVC 和 GCC 不接受它,我看了很多关于这个问题的答案,但我无法在 C++ 11 标准中获得有效的指针。
最佳答案
C++11, 5.6/2:
The operands of
*
and/
shall have arithmetic or unscoped enumeration type; the operands of%
shall have integral or unscoped enumeration type. The usual arithmetic conversions are performed on the operands and determine the type of the result.
(强调我的)
关于c++ - 在标准 (C++11) 的哪个地方说余数运算符仅适用于整数类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25529991/