码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-10-23 17:46:23      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:c   math.h   


                                                                           The remainder function and % operator.


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

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

int main()
{
	double x = 10;

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

	return 0;
}


operator  % 仅能操作在整形数据中,(猜测,%的实现是根据数据位shift实现的).

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



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

标签:c   math.h   

原文地址:http://blog.csdn.net/cinmyheart/article/details/40399665

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!