-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
numerical equality with =
and ==
#859
Comments
There have been multiple previous PRs and issues dealing with the issue of equality (see #556 and #585 for more details) and I've always come up with more questions than answers. I believe there are some areas not mentioned in your issue that are of more direct concern (namely inconsistencies in hashes for sequential collections):
However, I'm not personally convinced there's any need to match Clojure's behavior with respect to numeric equality specifically. As you pointed out, it was certainly done deliberately rather than unintentionally. That being said, you'll note even ClojureScript does not define equality on numbers in this way. I think without a clear bug (e.g. some behavior of some other functionality does not work as intended because of the decision compare all numerics for equality across "kinds") I would not like to change this behavior in Basilisp. |
There is a test case that I've encountered in our discourse of updating The first The second contrived case is the comparison of integer with floating points that are "close" to 1, e.g. basilisp.user=> (= 1 1.00000000000000009)
true Mathematically this is not correct, and it is only due to the technical limitations of IEEE floats we consider this by convention to be acceptable. Clojure gives users a choice in this instance by design (it seems). My only concern going with this approach is how performant the implemention be if we were to redefine If we are leaving Thanks |
In brief testing this was the cutoff point where equality was no longer the same between the integer 1 and a float with a small decimal value. >>> 1 == 1.0000000000000001
True
>>> 1 == 1.000000000000001
False While I'm sure there are cases where this is problematic, the difference seems more academic than practical in the vast majority of cases. I'm sure that's why Rich chose to do it for Clojure. But since it was not adopted for CLJS, there is obviously some tradeoff worth making here. As you also allude to, the performance impacts to all I'm not saying this is my absolute final decision and that I would never amend it, but at this moment in time it does not feel like a project worth doing.
As to this point, I am ok with simply defining |
Hi, could you please consider patch to add `==` as an alias for `=`. Fixes #859. I've also updated the doc to describe the difference of int vs float comparison in basilisp vs Clojure. Thanks --------- Co-authored-by: ikappaki <ikappaki@users.noreply.github.com>
Clojure has this concept with numerical equality that
=
returns true iff its arguments are numerically the same and fall under the same category:https://clojure.org/guides/equality
That means that if we compare an integer or a ratio with the floating point number in Clojure that have the same numericall value, it will return
false
:while in Basilisp
It appears to me this is a deliberate decision in the Clojure design, rather than a Java runtime decision, for example
Clojure also offers the less restricive
==
core fn, which soley compares numbers for numerical equality without considering the category (same as basilisp's=
)Is the Clojure behavior something we want to support in Basilisp or shall we define
==
the same as=
? I am inclining towards the first, but not sure what the implementation tradeoffs might be.Thanks
The text was updated successfully, but these errors were encountered: