初级会员
- 积分
- 194
- 金钱
- 194
- 注册时间
- 2011-5-17
- 在线时间
- 0 小时
|
我在stm32中做float数的乘法运算,结果小数部分总是被四舍五入了,感觉好奇怪哦,代码如下
float xreal[1024]={0};
float yimag[1024]={0};
float prodreal,prodimag,temp;
for(i=0;i<numdat;i++)
{
printf("%.5f^2+%.5f^2\t",xreal,yimag);
prodreal=xreal*xreal;
prodimag=yimag*yimag;
xreal=prodreal+prodimag;
printf("=%.5f+%.5f\t=%.5f\n",prodreal,prodimag,xreal);
}
下面是用串口打印出的值,
741.12372^2+-2469.41455^2 =549264.37500+6098008.00000 =6647272.50000
572.38074^2+-2276.23975^2 =327619.71875+5181267.50000 =5508887.00000
486.96545^2+-2376.88770^2 =237135.35938+5649595.00000 =5886730.50000
299.70471^2+-2256.29565^2 =89822.91406+5090870.00000 =5180693.00000
423.39056^2+-2101.43579^2 =179259.56250+4416032.50000 =4595292.00000
358.89664^2+-1871.71094^2 =128806.79688+3503301.75000 =3632108.50000
249.65945^2+-1441.64380^2 =62329.84375+2078336.87500 =2140666.75000
178.31213^2+-1561.17578^2 =31795.21680+2437269.75000 =2469065.00000
125.35099^2+-1537.33887^2 =15712.87109+2363410.75000 =2379123.50000
228.25537^2+-1681.80042^2 =52100.51562+2828452.75000 =2880553.25000
352.11523^2+-1356.63586^2 =123985.14062+1840460.87500 =1964446.00000
372.23483^2+-1263.69458^2 =138558.76562+1596924.00000 =1735482.75000
291.49051^2+-1208.13672^2 =84966.71875+1459594.37500 =1544561.12500
156.62329^2+-1303.51721^2 =24530.85547+1699157.12500 =1723688.00000
41.74076^2+-1247.06372^2 =1742.29114+1555167.87500 =1556910.12500
|
|