float value calculation result in vs2017 is different with vs2008

  • Thread starter Thread starter yxwfrank
  • Start date Start date
Y

yxwfrank

Guest
1. question 1, sample code:

short sVal = 9487;
float fFac = 10000.4311f;
float fMag = 1.127877f;
float ftemp1 = static_cast<float>(sVal) / fMag * fFac;
float ftemp2 = static_cast<float>(sVal) * fFac / fMag;
float fdiff = ftemp1 - ftemp2;
In vs2017, the value of fdiff is -8, but in vs2008, the fdiff is 0.

2. question 2, sample code:

short sVal = 9484;
float fFac = 0.43115962f;
float fMag = 1.12787700f;
float fNorm = static_cast<float>(sVal) / fMag * fFac ;
short sNorm= floorf(fNorm+0.5f);
In vs2017, sNorm is 3626, but in vs2008 sNorm is 3625.

fNorm in vs2017 is 3625.5000, in vs2008, fNorm is about 3625.4998.

I think the result in vs2008 is correct.

VS2017 version: professional, 15.9.13

Continue reading...
 
Back
Top