for(float i = 40; i <= 42; i+=0.1f)
{
float offset = (i-40) * 10 * sizeof(float);
int wtf = offset;
printf("%.1f =?= %d\n", offset, wtf);
fseek(fin, offset, SEEK_SET);
fread(&tf, sizeof(float), 1, fin);
//printf("%.1f %.4f\n", i, tf);
}
輸出:從浮奇怪轉換成int
0.0 =?= 0 4.0 =?= 3 8.0 =?= 7 12.0 =?= 11 16.0 =?= 15 20.0 =?= 19 24.0 =?= 23 28.0 =?= 27 32.0 =?= 31 36.0 =?= 35 40.0 =?= 39 44.0 =?= 43 48.0 =?= 47 52.0 =?= 51 56.0 =?= 55 60.0 =?= 59 64.0 =?= 63 68.0 =?= 67 72.0 =?= 71 76.0 =?= 75 80.0 =?= 79
我不明白這一點,你能幫幫我嗎?
你不瞭解什麼? – 2013-11-25 18:22:40
我強烈建議您閱讀[每位計算機科學家應瞭解的浮點算術知識](http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html) –