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
define deg2rad and rad2deg for any Number #22811
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.
lgtm! :)
Just by curiosity, why are all three methods needed instead of only the one added in this PR? |
@@ -165,6 +165,8 @@ julia> deg2rad(90) | |||
deg2rad(z::AbstractFloat) = z * (oftype(z, pi) / 180) | |||
rad2deg(z::Real) = rad2deg(float(z)) | |||
deg2rad(z::Real) = deg2rad(float(z)) | |||
rad2deg(z::Number) = (z/pi)*180 | |||
deg2rad(z::Number) = (z*pi)/180 |
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 think it would be better to have (z/180)*pi
to avoid overflow in special cases here.
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.
@musm, that just makes it possible to underflow...
@jebej, the old methods are more efficient for real numbers because they only do one multiplication rather than one multiplication and one division. |
You mean that the |
@jebej, yes. (Look at |
Will merge soon as this seems uncontroversial. |
deg2rad
andrad2deg
were previously defined only forReal
, but there is no reason not to define them for anyNumber
type for completeness, and this could occasionally be useful as I commented on discourse.The fallback definitions added by this PR are somewhat suboptimal for
Complex
, but I don't see this as a real problem (no pun intended). I can't imagine a performance-sensitive case where this would be applied to complex numbers without being combined with some much more expensive function likesin
. And of course, optimized methods could be added later if there is a need.