64,660
社区成员
发帖
与我相关
我的任务
分享
float f = 0.1;
float sum = 0;
for( i=0; i<4000000; i++)
{
sum += f;
}
printf("%d\n", (int)(4000000.0 * 0.1));
float s = 0;
int intpart = 0;
for(int i=0; i< 4000000; i++)
{
s += (float)0.1;
intpart += (int)s;
s -= (int)s;
}
printf("%d\n", (int)(s + intpart));
int main()
{
float f = 0.1;
float sum = 0;
sum+=add(f,4000000);
cout<<sum<<endl;
return 0;
}
float add(float f,int count)
{
if(count==1)
return f;
else
return add(f,count/2)+add(f,count-count/2);
}
结果是400000
当然函数调用开销是另一回事