I'm facing float point precision problem in my C++ code
given double d = 32.4;
d / 0.01 == 3240.0;
gives true, while
d / 0.1 == 324.0
gives false.
But if I multiple by 10 and 100 then the result are both true.
Since 32.4, 324 and 3240 can all be represented by 64bit double without any precision loss, so this result is quite confusing to me. (I'm not very familiar with multiplier and divident operation in float point)
In my use case, I will do some conversion among different scale, by simpliy multiplying or dividing something like 0.1, 0.01, 0.05. I mean, I don't require very high precision, my operands are usually less than 6 decimals, which can be represent in 64bit double without precision loss, so I want to get consistent result. I have a guess: should I always use multiplying instead of dividing in my use case?