什么代表C++中的Math.IEEERemainder(x,y)?

Ahm*_*rid 4 c++

什么代表C++中的Math.IEEERemainder(x,y)

SLa*_*aks 7

试试fmod功能.

  • +1."使用模数运算符"效果的答案错过了模数与fmod不同的操作点. (2认同)

dec*_*lts 5

在 C++11 标准库中,std::remainder(x,y),现在相当于 C++ 中 C# 的函数Math.IEEERemainder(x,y)

\n\n

来自: http: //en.cppreference.com/w/cpp/numeric/math/remainder

\n\n
\n

计算浮点除法运算的 IEEE 余数x/y

\n
\n\n

IEEE 余数为x\xe2\x80\x93(round(x/y)*y)

\n\n

fmod余数是x - trunc(x/y)*y,这可能会导致不同的答案,例如在这个问题中提出的:Why am I get a different result from std::fmod and std::remainder

\n\n

如果您确实想获得 IEEE 定义的余数,您需要std::remainder(x,y)(或者如果您不能使用 C++11,则定义您自己的函数)

\n