1

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 tf1is 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?

Andi
  • 3,196
  • 2
  • 24
  • 44
  • 1
    Change format to `format longe`. Now run `101/100-1`, and then run `0.01` See if these are equal or not. Read the duplicate target for details – Sardar Usama Feb 21 '17 at 13:12

0 Answers0