在 C++11 标准库中,std::remainder(x,y),现在相当于 C++ 中 C# 的函数Math.IEEERemainder(x,y)。
来自: http: //en.cppreference.com/w/cpp/numeric/math/remainder
\n\n\n\n\n计算浮点除法运算的 IEEE 余数
\nx/y
IEEE 余数为x\xe2\x80\x93(round(x/y)*y)
而fmod余数是x - trunc(x/y)*y,这可能会导致不同的答案,例如在这个问题中提出的:Why am I get a different result from std::fmod and std::remainder
如果您确实想获得 IEEE 定义的余数,您需要std::remainder(x,y)(或者如果您不能使用 C++11,则定义您自己的函数)