C语言双精度浮点余数:fmod()
例子
此函数返回的除法的浮点余数x/y。返回的值与x相同。
#include <math.h> /* for fmod() */
#include <stdio.h> /* for printf() */
int main(void)
{
double x = 10.0;
double y = 5.1;
double modulus = fmod(x, y);
printf("%lf\n", modulus); /* f is the same as lf. */
return 0;
}输出:
4.90000
重要:请谨慎使用此函数,因为由于浮点值的操作,它可能返回意外的值。
#include <math.h>
#include <stdio.h>
int main(void)
{
printf("%f\n", fmod(1, 0.1));
printf("%19.17f\n", fmod(1, 0.1));
return 0;
}输出:
0.1 0.09999999999999995
热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短