Closed ianmackenzie closed 2 weeks ago
My gut feeling is that they should be equal (if of the same sign ofc)
I'd also be for having these functions treat infinities as equal, especially since (1/0) == (1/0)
.
OK I've updated the code to return equal for (same-sign) infinities - I don't love it, but if you're trying to compare infinities for approximate equality something's probably already gone wrong 😅
I've merged this manually. If there are any further changes then let's make them as separate PRs.
One thing to consider: should
Float.Extra.equalWithin 1 (1 / 0) (1 / 0)
returnTrue
, i.e. should infinite be considered (exactly) equal to itself? The current code will always return false when comparing two infinities since the difference between two infinities is not well defined...but this is arguably inconsistent withaboutEqual
which does consider infinities of the same sign to be "about equal". (You could maybe argue that's becauseaboutEqual
uses relative instead of absolute tolerance, but I think it would also make sense to changeaboutEqual
to always return false for infinities.)