There is an interesting question on Facebook which I encountered. He asks that he is using MATLAB R2014a (64-bit version) and ran this code:-
x = 0.45;
min = fix((x)*60);
fprintf('min = %d \n', min);
x = 20.45
min = fix((x-20)*60);
fprintf('min = %d \n', min);
The results are following:
>> tx
min = 27
min = 26
which are incorrect because (20.45 - 20) should give the same result as 0.45, but it does not.
He also attempted %f but it still gave the same result.
At first, I thought it was problem with storing floating point but after I calculated it, it did not seem to be the right answer.
So, I think this question is interesting and challenging. Could anyone please help me explain how this happens?
Thanks!