I stumbled upon some weird MATLAB behavior while running a unit test. I do receive some "incorrect" or "unprecise" results when computing the percentage change of two data points. For illustrative purpose, take a look at the following example.
test1 = 101/100-1 % test1 = 0.01
tf1 = isequal(test1, 0.01) % tf1 = false
On my machine tf1
is false
, which is clearly wrong as test1
should exactly be equal to 0.01
. In the first place I thought this might have something to do with the division resulting in a "rounding" error.
However, if you avoid the substraction (-1) in the first place, tf
becomes true
.
test2 = 101/100 % test2 = 1.01
tf2 = isequal(test2, 1.01) % tf2 = true
Now, I am a bit confused and I am wondering what is going on?