Skip to content

Commit

Permalink
atan2 -> atan
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed May 24, 2018
1 parent 779cf84 commit 9d83cff
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
8 changes: 4 additions & 4 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ julia> rad2deg(angle(-1 - im))
-135.0
```
"""
angle(z::Complex) = atan2(imag(z), real(z))
angle(z::Complex) = atan(imag(z), real(z))

function log(z::Complex{T}) where T<:AbstractFloat
T1::T = 1.25
Expand Down Expand Up @@ -808,7 +808,7 @@ function asin(z::Complex)
end
ξ = zr == 0 ? zr :
!isfinite(zr) ? oftype(zr,pi)/2 * sign(zr) :
atan2(zr, real(sqrt(1-z)*sqrt(1+z)))
atan(zr, real(sqrt(1-z)*sqrt(1+z)))
η = asinh(copysign(imag(sqrt(conj(1-z))*sqrt(1+z)), imag(z)))
Complex(ξ,η)
end
Expand All @@ -829,7 +829,7 @@ function acos(z::Complex{<:AbstractFloat})
elseif zr==-Inf && zi===-0.0
return Complex(oftype(zi,pi), -zr)
end
ξ = 2*atan2(real(sqrt(1-z)), real(sqrt(1+z)))
ξ = 2*atan(real(sqrt(1-z)), real(sqrt(1+z)))
η = asinh(imag(sqrt(conj(1+z))*sqrt(1-z)))
if isinf(zr) && isinf(zi) ξ -= oftype(η,pi)/4 * sign(zr) end
Complex(ξ,η)
Expand Down Expand Up @@ -890,7 +890,7 @@ function acosh(z::Complex)
return Complex(oftype(zr,Inf), oftype(zi, -pi))
end
ξ = asinh(real(sqrt(conj(z-1))*sqrt(z+1)))
η = 2atan2(imag(sqrt(z-1)),real(sqrt(z+1)))
η = 2*atan(imag(sqrt(z-1)),real(sqrt(z+1)))
if isinf(zr) && isinf(zi)
η -= oftype(η,pi)/4 * sign(zi) * sign(zr)
end
Expand Down
23 changes: 18 additions & 5 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,13 @@ Compute hyperbolic tangent of `x`.
tanh(x::Number)

"""
atan(x)
atan(y)
atan(y, x)
Compute the inverse tangent of `x`, where the output is in radians.
Compute the inverse tangent of `y`, where the output is in radians.
"""
atan(x::Number)
atan(x::Number)

"""
asinh(x)
Expand Down Expand Up @@ -508,11 +510,22 @@ hypot(x::Number...) = sqrt(sum(abs2(y) for y in x))
"""
atan2(y, x)
Compute the inverse tangent of `y/x`, using the signs of both `x` and `y` to determine the
quadrant of the return value.
This is also available via [`atan`](@ref), but `atan2` is provided for compatibility
purposes.
"""
atan2(y, x) = atan(y, x)

"""
atan(y, x)
Compute the inverse tangent of `y/x`, using the signs of both `x` and `y` to determine the
quadrant of the return value.
"""
atan2(y::Real, x::Real) = atan2(promote(float(y),float(x))...)
atan2(y::T, x::T) where {T<:AbstractFloat} = Base.no_op_err("atan2", T)
atan(y::Real, x::Real) = atan(promote(float(y),float(x))...)
atan(y::T, x::T) where {T<:AbstractFloat} = Base.no_op_err("atan", T)

max(x::T, y::T) where {T<:AbstractFloat} = ifelse((y > x) | (signbit(y) < signbit(x)),
ifelse(isnan(x), x, y), ifelse(isnan(y), y, x))
Expand Down Expand Up @@ -958,7 +971,7 @@ for func in (:sin,:cos,:tan,:asin,:acos,:atan,:sinh,:cosh,:tanh,:asinh,:acosh,
end
end

for func in (:atan2,:hypot)
for func in (:atan,:hypot)
@eval begin
$func(a::Float16,b::Float16) = Float16($func(Float32(a),Float32(b)))
end
Expand Down
4 changes: 2 additions & 2 deletions base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import
sum, sqrt, string, print, trunc, precision, exp10, expm1,
gamma, lgamma, log1p,
eps, signbit, sin, cos, sincos, tan, sec, csc, cot, acos, asin, atan,
cosh, sinh, tanh, sech, csch, coth, acosh, asinh, atanh, atan2,
cosh, sinh, tanh, sech, csch, coth, acosh, asinh, atanh,
cbrt, typemax, typemin, unsafe_trunc, realmin, realmax, rounding,
setrounding, maxintfloat, widen, significand, frexp, tryparse, iszero,
isone, big, beta, RefValue
Expand Down Expand Up @@ -677,7 +677,7 @@ end

lgamma_r(x::BigFloat) = (lgamma(x), lgamma_signp[])

function atan2(y::BigFloat, x::BigFloat)
function atan(y::BigFloat, x::BigFloat)
z = BigFloat()
ccall((:mpfr_atan2, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}, Ref{BigFloat}, Int32), z, y, x, ROUNDING_MODE[])
return z
Expand Down
2 changes: 1 addition & 1 deletion base/number.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ copysign(x::Real, y::Real) = ifelse(signbit(x)!=signbit(y), -x, +x)
conj(x::Real) = x
transpose(x::Number) = x
adjoint(x::Number) = conj(x)
angle(z::Real) = atan2(zero(z), z)
angle(z::Real) = atan(zero(z), z)

"""
inv(x)
Expand Down
2 changes: 1 addition & 1 deletion base/special/trig.jl
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ ATAN2_PI_LO(::Type{Float64}) = 1.2246467991473531772E-16
ATAN2_RATIO_BIT_SHIFT(::Type{Float64}) = 20
ATAN2_RATIO_THRESHOLD(::Type{Float64}) = 60

function atan2(y::T, x::T) where T<:Union{Float32, Float64}
function atan(y::T, x::T) where T<:Union{Float32, Float64}
# Method :
# M1) Reduce y to positive by atan2(y,x)=-atan2(-y,x).
# M2) Reduce x to positive by (if x and y are unexceptional):
Expand Down

0 comments on commit 9d83cff

Please sign in to comment.