Hacker News new | ask | show | jobs
by conradludgate 2000 days ago
Comparing floats by equality is a dangerous pattern. It's easy for small precision errors to occur. You should instead check that they are close enough to each other, using an epsilon that you find appropriate, perhaps 1e-10. `(x - y).abs() < epsilon` should do the trick
2 comments

I know, it's an example I was hoping clippy would catch in order for it to fail so I know it works. Read what I wrote...
It's in fact the dangerous pattern used to illustrate the linter under discussion here.