见下面的code: float param=0.0, fractpart=0.0, intpart=0.0; param = 3.141; fractpart = modf (param , &intpart); printf ("Result: %f = %f + %f \r\n", param, intpart, fractpart); fractpart = fmod (param , &intpart); printf ("Result: %f = %f + %f \r\n", param, intpart, fractpart); -------------------------- Result: 3.141000 = 0.000000 + 537170816.000000 Result: 3.141000 = 0.000000 + 0.000000 我是在F756上跑的。 看起来这两个函数 modf和 fmod都不能正确给出计算结果。请问是什么原因?有其他替代函数吗?谢谢! |
float fractpart=0.0;
double intpart=0.0;
double param=0.0;
param = 3.141;
fractpart = modf (param , &intpart);
printf ("Result: %f = %f + %f \r\n", param, intpart, fractpart);
fractpart = fmod (param , intpart);
printf ("Result: %f = %f + %f \r\n", param, intpart, fractpart);