-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Generalize some definitions for Irrational
to AbstractIrrational
#48768
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes to ==
, <
, and <=
might be fine if AbstractIrrational
were only ever used to implement constants which are fully specified by their type. However, this is not true throughout the ecosystem: see e.g. RationalRoots.jl or MultiplesOfPi.jl. Is it really too much of a burden to define these methods in packages when this is the correct implementation? When it is not, a MethodError
is a much better user outcome than a wrong result.
I thought it would be a reasonable default but I can see that it might not be correct in all cases and hence maybe one would want to remove it from this PR. I think there are a few things to consider here:
I think the other generalizations should be less controversial and I could also split the PR, if desired. |
Thanks, this is a good point. I brought this up back in #26550, and at the time it seemed the consensus was that if someone was creating a type that derived from |
The current fallbacks can be wrong even in cases where no non-irrational numbers and only constants are involved, so one doesn't have to consider such special cases which possibly might require some custom treatment and additional overloads anyway. The |
Bump 🙂 I still think lifting some of the type restrictions would be helpful for downstream packages such as IrrationalConstants. |
In IrrationalConstants 0.2 we recently switched to custom irrational types
<: AbstractIrrational
(created by a custom@irrational
macro) to fix type piracy (see e.g. #46531). During that transition we noticed that we had to copy existing code in base that currently does not supportAbstractIrrational
(and hence not our custom irrational types), e.g., https://github.com/JuliaMath/IrrationalConstants.jl/blob/c9a73a62a9e2f90abe3b1a3f92edeb487fcc9f8d/src/macro.jl#L7-L18 and JuliaMath/IrrationalConstants.jl#24.This PR widens some of these definitions which should allow us to remove the downstream code at some point. I did not know if it would be safe to generalize
hash
as well (I'm not familiar with why it is defined the way it is), so I did not include it in the initial commit.