C++中 double 类型数据取模
C++ 中的取模运算符 % 操作数是 int 类型,如果需要对 double 类型的数据进行取模操作,需要使用到 std::fmod(double, double)
如 x 对 y 进行取模操作,
#include <cmath>
double x = 6.2, y = 5.6;
// 返回结果为: 0.6
double retMod = std::fmod(x, y);
其它的一些取模操作:
float fmod ( float x, float y );long double fmod ( long double x, long double y );
[参考资料]
std::fmod
浙公网安备 33010602011771号