【总结】C/C++取余操作:%、fmod()、remainder()的区别和联系

定义

fmod

double fmod (double numer     , double denom);
float fmod (float numer      , float denom);
long double fmod (long double numer, long double denom);
double fmod (Type1 numer      , Type2 denom);       // additional overloads

Compute remainder of division
Returns the floating-point remainder of numer/denom (rounded towards zero):

fmod = numer - tquot * denom 

Where tquot is the truncated (i.e., rounded towards zero) result of: numer/denom.

remainder

double remainder (double numer     , double denom);
float remainder (float numer      , float denom);
long double remainder (long double numer, long double denom);
double remainder (Type1 numer      , Type2 denom);       // additional overloads

Compute remainder (IEC 60559)
Returns the floating-point remainder of numer/denom (rounded to nearest):

remainder = numer - rquot * denom 

Where rquot is the result of: numer/denom, rounded toward the nearest integral value (with halfway cases rounded toward the even number).

%

int numer
int denom
numer%denom
取模运算符,是算术运算符的一种。操作数只能是整数。
返回整除后的余数。

联系

1.都是取余运算

未完待续

c++# c, denom, numer

版权声明

本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处。如若内容有涉嫌抄袭侵权/违法违规/事实不符,请点击 举报 进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部