-
-
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
Remove the type constraint on sincosd
#41021
Conversation
I can't add test here, so I just paste the test in this PR: julia> using Unitful, Test
julia> sincosd(5u"°")
ERROR: MethodError: no method matching sincosd(::Quantity{Int64, NoDims, Unitful.FreeUnits{(°,), NoDims, nothing}})
Closest candidates are:
sincosd(::Real) at special/trig.jl:1249
sincosd(::Missing) at special/trig.jl:1261
Stacktrace:
[1] top-level scope
@ REPL[1]:1
julia> function Base.sincosd(x)
if isinf(x)
return throw(DomainError(x, "sincosd(x) is only defined for finite `x`."))
elseif isnan(x)
return (oftype(x,NaN), oftype(x,NaN))
end
# It turns out that calling those functions separately yielded better
# performance than considering each case and calling `sincos_kernel`.
return (sind(x), cosd(x))
end
julia> sincosd(5u"°")
(0.08715574274765818, 0.9961946980917455)
julia> @test sind(5u"°") == sind(5) == 0.08715574274765818
Test Passed
julia> @test cosd(5u"°") == cosd(5) == 0.9961946980917455
Test Passed |
Wouldn't it make more sense to change the type to |
|
Yes, but that method actually works for The method defined here will only ever work for numbers. |
Ok, I think |
Co-authored-by: Jameson Nash <[email protected]>
Didn't we get |
Now that the function has been redefined to just call through to |
You could add tests with |
I actually want to add tests against |
No, we don’t use |
Can someone tell me should |
I'm pretty sure that |
What about |
I think In fact, |
I agree. There should be a native Julia type for |
See #26362 for discussion of a |
That's unfortunate. I wonder if it's still possible to do this. |
Co-authored-by: Steven G. Johnson <[email protected]>
Co-authored-by: Jameson Nash <[email protected]> Co-authored-by: Steven G. Johnson <[email protected]>
Co-authored-by: Jameson Nash <[email protected]> Co-authored-by: Steven G. Johnson <[email protected]>
Closes #41017