问题:
我们这边发现vxworks的fmod计算出来的结果是有问题的。
比如 9.3/3.0 结果为 -2.7,而 11.2/3.0 结果为2.2。测试用例:double Test_fmod(double a, double b)
{
double i;
double j,k,m, c;
double aa, bb;
i = 10.0;
j = 2.0;
k = 3.5;
aa = a;
bb = b;
m = fmod( i,j );
printf("fmod(%f,%f ), is %f\r\n", i, j, m);
m = fmod( i,k );
printf("fmod(%f,%f ), is %f\r\n", i, k, m);
m = fmod( i,k );
printf("fmod(%f,%f ), is %f\r\n", i, k, m);
i = 11.5;
j = 2.1;
m = fmod( i,j);
printf("fmod(%f,%f ), is %f\r\n", i, j, m);
i = 11.5;
j = 0.0;
m = fmod( i,j );
printf("fmod(%f,%f ), is %f\r\n", i, j, m);
i = 11.5;
j = 1.8;
m = fmod( i,j );
printf("fmod(%f,%f ), is %f\r\n", i, j, m);
i = 12.0;
j = 12.0;
m = fmod( i,j );
printf("fmod(%f,%f ), is %f\r\n", i, j, m);
c = fmod( aa, bb);
printf("fmod(%f,%f ), is %f\r\n", aa, bb, c);
return m;
}
测试结果:
fmod(10.000000,2.000000 ), is 1.000000
fmod(10.000000,3.500000 ), is 1.000000
fmod(10.000000,3.500000 ), is 1.000000
fmod(11.500000,2.100000 ), is 1.000000
fmod(11.500000,0.000000 ), is 0.000000
fmod(11.500000,1.800000 ), is 1.000000
fmod(12.000000,12.000000 ), is 1.000000fmod(10.000000,2.000000 ), is 1.000000
fmod(10.000000,3.500000 ), is 1.000000fmod(5.000000,2.500000 ), is 1.000000
fmod(5.000000,1.500000 ), is 1.000000fmod(5.000000,3.500000 ), is 1.000000
fmod(5.000000,2.100000 ), is 1.000000
在使用的时候需要增加include文件
#include
#include
因为fmod的实现有两个地方,一个是fmod.c还有一个是ansiMath.c,不使用这两个包含文件可能调了不同的文件。
测试的时候需要注意:
1、不能在shell上输入命令的时候带浮点参数,shell对参数传递使用了固定的寄存器,浮点的参数传不进去。
2、如果在任务中使用了浮点,任务创建的时候需要带VX_FP_TASK选项。
在不增加include情况下的输出:
fmod(10.000000,2.000000 ), is 1.000000
fmod(10.000000,3.500000 ), is 1.000000
fmod(10.000000,3.500000 ), is 1.000000
fmod(11.500000,2.100000 ), is 1.000000
fmod(11.500000,0.000000 ), is 0.000000
fmod(11.500000,1.800000 ), is 1.000000
fmod(12.000000,12.000000 ), is 1.000000
fmod(10.100000,2.600000 ), is 1.000000
增加了include以后的输出:
fmod(10.000000,2.000000), is 0.000000
fmod(10.000000,3.500000), is 3.000000
fmod(10.000000,3.500000), is 3.000000
fmod(11.500000,2.100000), is 1.000000
fmod(11.500000,0.000000), is NaN
fmod(11.500000,1.800000), is 0.700000
fmod(12.000000,12.000000), is 0.000000
fmod(10.100000,2.600000), is 2.300001
后面的结果应该是对的
阅读(997) | 评论(0) | 转发(0) |