-
-
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
copysign and flipsign aren't type stable with Irrational input #21535
Comments
It seems to me that you're better off just calling |
I don't have particular problems, but thought it was preferable to have functions in Base type-stable when possible. |
The fact that
(I once started writing an IrrationalExpressions package that could resolve this, but it's been on hold for a while.) |
A simple fix would be to create negative counterparts to each |
We've been quite strict about not making Irrationals an algebraic type by adding more and more arithmetic to them – because that is a very slippery slope – but I suppose negation is simple and restricted enough that this could be defensible. |
I completely agree. I'm often hit by the fact that
That would also complement |
I've occasionally thought of extending irrationals to rational multiples of irrational values, but then you have a problem in that some of the computation with big floats may end up happening at runtime, which is extremely undesirable, so it still seems best not to go there. |
If we add negation, will we be able to resist and not add the inverse later? I'm afraid not... |
Yes, that's precisely the slippery slope here. |
I think inversion is much more complex than negation. Negation changes only the sign, inversion affects the module. Personally, I wouldn't support even |
What if irrational arithmetic were allowed via a macro? So |
That macro could be implemented in a package, which seems like a good way to explore the idea. |
If you use 2pi frequently, you could use the Tau.jl package here. |
It seems that the copysign(x::Real, y::Real) = ifelse(signbit(x)!=signbit(y), -x, +x) I think function copysign(x::Real, y::Real)
R = promote_type(typeof(+x), typeof(-x))
R(ifelse(signbit(x)!=signbit(y), -x, +x))
end |
I'm not sure what's the best solution. Maybe defining
?
The text was updated successfully, but these errors were encountered: