在这里,我从浮点变量中减去 128.0 和 129.0 2M 次。
#include "stdafx.h"
#include<stdlib.h> //is this the problem? Or am i doing something wrong?
int main()
{
float d1=3.0e9;
printf("\n before: %f \n",d1);
for(int i=0;i<2000000;i++) d1=d1-128.0; //doesnt change!
printf("\n after : %f \n",d1);
for(int i=0;i<2000000;i++) d1=d1-129.0; //does change!
printf("\n after2: %f \n",d1);
//is 129 is the minimum step for sub/add ? Isnt this wrong?
//Is this about exponential part 10^9 ?
getchar();
return 0;
}
输出:
问题:为什么这个浮点数不会通过添加/替换小于 129 的操作数来改变?因为我选择了初始浮点值 3.0e9 ?
当我选择初始值 3.0e10 时,初始化和减法都不起作用。
当我选择初始值 3.0e8 时,最小变化是 17。所以 16 不会改变。:(
所以,谢谢你的回答,。当初始值变小时,最小步长根据精度变小。
VC++ 2010 速成 . windows xp 32位。奔腾-m