C++中 double 类型数据取模

C++ 中的取模运算符 % 操作数是 int 类型,如果需要对 double 类型的数据进行取模操作,需要使用到 std::fmod(double, double)

xy 进行取模操作,

#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

posted @ 2024-01-03 17:26  Jeffxue  阅读(255)  评论(0编辑  收藏  举报