core-extra icon indicating copy to clipboard operation
core-extra copied to clipboard

Add Float.Extra.[equalWithin,interpolateFrom]

Open ianmackenzie opened this issue 1 year ago • 3 comments

One thing to consider: should Float.Extra.equalWithin 1 (1 / 0) (1 / 0) return True, 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 with aboutEqual which does consider infinities of the same sign to be "about equal". (You could maybe argue that's because aboutEqual uses relative instead of absolute tolerance, but I think it would also make sense to change aboutEqual to always return false for infinities.)

ianmackenzie avatar Mar 26 '24 02:03 ianmackenzie

My gut feeling is that they should be equal (if of the same sign ofc)

miniBill avatar Mar 26 '24 08:03 miniBill

I'd also be for having these functions treat infinities as equal, especially since (1/0) == (1/0).

gampleman avatar Mar 26 '24 14:03 gampleman

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 😅

ianmackenzie avatar Mar 27 '24 03:03 ianmackenzie

I've merged this manually. If there are any further changes then let's make them as separate PRs.

gampleman avatar Sep 21 '24 15:09 gampleman