单、双精度的浮点数为什么不能进行取余运算?

a1988lourong 2011-10-17 09:41:12
单、双精度的浮点数为什么不能进行取余运算?
...全文
1508 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hulongchuan 2011-10-18
  • 打赏
  • 举报
回复
因为带小数点的,永远也求不出他的余数是多少!自然也就不能取模。
luciferisnotsatan 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 supermegaboy 的回复:]

%是用于整数的,浮点数用fmod函数。
[/Quote]
++
追求执着 2011-10-18
  • 打赏
  • 举报
回复
这个我也不知道,学习楼上!
a1988lourong 2011-10-18
  • 打赏
  • 举报
回复
谢谢各位的帮忙
赵4老师 2011-10-18
  • 打赏
  • 举报
回复
fmod
Calculates the floating-point remainder.

double fmod( double x, double y );

Function Required Header Compatibility
fmod <math.h> ANSI, Win 95, Win NT


For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version


Return Value

fmod returns the floating-point remainder of x / y. If the value of y is 0.0, fmod returns a quiet NaN. For information about representation of a quiet NaN by the printf family, see printf.

Parameters

x, y

Floating-point values

Remarks

The fmod function calculates the floating-point remainder f of x / y such that x = i * y + f, where i is an integer, f has the same sign as x, and the absolute value of f is less than the absolute value of y.

Example

/* FMOD.C: This program displays a
* floating-point remainder.
*/

#include <math.h>
#include <stdio.h>

void main( void )
{
double w = -10.0, x = 3.0, y = 0.0, z;

z = fmod( x, y );
printf( "The remainder of %.2f / %.2f is %f\n", w, x, z );
printf( "The remainder of %.2f / %.2f is %f\n", x, y, z );

}


Output

The remainder of -10.00 / 3.00 is -1.000000


Floating-Point Support Routines

See Also ceil, fabs, floor
quwei197874 2011-10-17
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 supermegaboy 的回复:]
%是用于整数的,浮点数用fmod函数。
[/Quote]++
飞天御剑流 2011-10-17
  • 打赏
  • 举报
回复
%是用于整数的,浮点数用fmod函数。
LinuxBirdMan 2011-10-17
  • 打赏
  • 举报
回复
问C语言之父去,他在那里等你~~

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧