-1

The expression 0.09==0.1-0.01 gives false, but for example 0.08==0.1-0.02 is true and 0.19==0.2-0.01 is also true. What is the problem?

Tomi27
  • 101
  • 3

1 Answers1

1

This is a classical rounding error. Usually if you compare floats you use an Epsilon, which defines how close two floating point numbers must be to each other to assume they are the same number.

See:

http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-0.2-0.1.28or_similar.29_not_equal_to_zero.3F

Koenigsberg
  • 1,726
  • 1
  • 10
  • 22