-
-
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
Fix sincos
for reals that are not AbstractFloats
#25292
Conversation
base/special/trig.jl
Outdated
@@ -197,7 +197,9 @@ function sincos(x::T) where T<:Union{Float32, Float64} | |||
return -co, si | |||
end | |||
end | |||
sincos(x::Real) = sincos(float(x)) | |||
sincos(x::T) where {T <: Union{Integer, Rational}} = sincos(float(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.
What about irrational?
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.
That's covered by the old definition that's kept below.
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.
Yes, but irrationals don't use the faster version, right? (I'm on my phone, I can't check myself right now)
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.
Oh, my bad, of course you're right, it should be {Integer, Rational, Irrational}
. The current changes makes sincos(pi)
slower than before.
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.
Ah, good point, thanks, I'll change it.
I don't understand how to interpret the test errors -- can anybody help me?
|
Is irrational not defined at this point? |
Apparently not. Also, in the future we may want to define sin(pi) etc explicitly. So I think it's better to leave the generic definition to cover irrationals. |
Practically speaking this should be of no real importance, but do you then propose that sincos(someotherrational) should be slow? Or do you want to define sin for all irrationals? |
I have now implemented @yuyichao's approach from #22095 (comment) and left a generic fallback. |
The current failures seem unrelated (being in the |
It is related
|
That is a very unfortunately specific test. It should be revised or removed so this can be merged. |
Change |
I have now reimplemented the logic using multiple dispatch instead. Not sure what the test failures are about now. They seem unrelated? |
Made a big rebase/merge mess again, sorry. How do I back myself out of this one? |
Have now fixed the mess by cherry-picking onto latest master and force pushing. |
sincos
for non-standard subtypes of Real
sincos
for reals that are not AbstractFloats
Are the failures in Circle x86_64 related? If not, then this is ready to go. |
Fixes #22095.
This PR adds a generic fallback for
sincos
.This allows
exp(a + im*b)
to work correctly when the type ofa
andb
is a non-standard subtype ofReal
(e.g.ArbFloat
orInterval
).There is a test provided with the simplest such non-standard type.
[Note that this -- EDIT: that is,
exp(a + im*b)
-- worked in Julia 0.6, but does not work in current master, so this is in fact a bug fix for a regression and not a new feature.]