double x = 10 ,y = 0;y = x % 2; 这个表达式正确吗?


                                                                           The remainder function and % operator.


               以下这段代码过不了编译的(gcc)

#include <stdio.h>
#include <fenv.h>

int main()
{
	double x = 10;

	printf("x % 2 = %lf
",x%2.0);

	return 0;
}


operator  % 仅能操作在整形数据中,(推測,%的实现是依据数据位shift实现的).

这里浮点数的取余数调用<math.h> 里面的fmod(doube x,double y)就可以



原文地址:https://www.cnblogs.com/yfceshi/p/6911909.html