elmcraft / core-extra

Utility functions for an improved experience with elm/core
https://package.elm-lang.org/packages/elmcraft/core-extra/latest/
Other
23 stars 11 forks source link

Add Float.Extra.[equalWithin,interpolateFrom] #54

Closed ianmackenzie closed 2 weeks ago

ianmackenzie commented 6 months ago

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.)

miniBill commented 6 months ago

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

gampleman commented 6 months ago

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

ianmackenzie commented 6 months ago

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 😅

gampleman commented 2 weeks ago

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