Float Substraction returns wrong result in Julia

Viewed 55

I tried the following in the REPL:

a = 0.0002 - 0.0001
> 0.0001

b = 0.0003 - 0.0002
> 9.999999999999996e-5

a == b
> false

Why is b not 0.0001 as well? I understand that Float64, like any other type, can have rounding errors, but is this what I'm seeing here?

It's actually a julia package that does this subtraction and check process with some time values (0.0001, 0.0002, ...) that I provide and it crashes because of it. Is there something I can do without modifying the code of that package?

0 Answers
Related