Sunday, 15 February 2015

floating point - Read float wrong value from txt file c++ -



floating point - Read float wrong value from txt file c++ -

i have text file of values:

133.25 129.40 41.69 2.915

when read it:

fscanf(file, "%f", &floatnumber[i]);

i these values:

1.3325000000000000e+002, 1.2939999389648437e+002, 4.1689998626708984e+001 2.9149999618530273e+000

the first value okay other 3 values why different?

the values same, need alter format specificier in printf.

also, floating point numbers have discrete precision, hence not possible reprenent arbitrary floating point numbers infinite accuracy.

this well-known problem ieee spec.

c++ floating-point

No comments:

Post a Comment