3 ms·
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
by gweinberg 5y ago
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.
- eru 5y agoAdding floating point numbers is dangerous, too.
- Tainnor 5y agoCan 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.
- eru 5y agoAlas, 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.
- Tainnor 5y agoIt'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?)