Hacker News new | past | comments | ask | show | jobs | submit login

Yeah, pretty much the only case I can think of when you'd want to check floating points for equality is for bug hunting e.g. if you calculate a set of disjoint probabilities you might want to verify that they add up to 1.



Adding floating point numbers is dangerous, too.


Can you explain? In the case that all floating point numbers have the same sign (in this example, probabilities), I thought addition was well behaved.

I was taught that you can only get into trouble when you e.g. subtract two approximately equal values from each other.


Alas, addition isn't well-behaved.

Eg when you want to add a list of (non-negative) numbers, it makes a difference what order you add them in. The usual recommendation is to add them in ascending order.


It's not commutative, yes, but it should still obey the property that the relative error terms add instead of multiplying, no?

(i.e. in the parent's case of "checking that, if you add a bunch of disjoint probabilities, they're at most 1", doing that with approximate equality seems fine to me?)




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: