-
-
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
ispow2(x) for non-Integer x #37635
ispow2(x) for non-Integer x #37635
Conversation
3e071b1
to
9d3ab9e
Compare
CI errors seem unrelated:
on tester_macos64 and
on package_linuxaarch64. |
""" | ||
ispow2(x::Number) = isreal(x) && ispow2(real(x)) |
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.
Maybe this should be restricted to Complex
, since there isn't a fallback covering all Real values.
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.
I feel like there should be a way to throw a MethodError
for common patterns like this, rather than StackOverflowError
. I've bumped into similar issues many times, e.g. with f(x) = f(float(x))
patterns.
Could we implement something like
@norecurse ispow2(x::Number) = isreal(x) && ispow2(real(x))
?
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.
(For example, this Number
method would work perfectly well for quaternion types. It seems a shame to lose genericity due to dispatch limitations.)
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.
I agree.
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.
With @stevengj's approach ^, the work of making types consistent inside and collaboratively correct outside is a touch simpler.
@norecurse fn(x::Real) = fn(float(x))
dispatch resolves giving attentive safety
Seemed like there is no reason to limit
ispow2(x)
tox::Integer
.