News for hackers. Stuff that matters.
Re:How to compare floats in Python by Tainnor on Thursday March 31, 2022 @05:38AM (#30865375)
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.

Re:How to compare floats in Python by eru on Thursday March 31, 2022 @07:59PM (#30873666)
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.

Re:How to compare floats in Python by Tainnor on Friday April 01, 2022 @01:00PM (#30880486)
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?)