Skip to content
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

atan2 -> atan #27253

Merged
merged 2 commits into from
Jun 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,8 @@ Deprecated or removed

* `setrounding` has been deprecated for `Float32` and `Float64`, as the behaviour was too unreliable ([#26935]).

* `atan2` is now a 2-argument method of `atan` ([#27248]).

Command-line option changes
---------------------------

Expand Down Expand Up @@ -1591,3 +1593,4 @@ Command-line option changes
[#27164]: https://github.com/JuliaLang/julia/issues/27164
[#27189]: https://github.com/JuliaLang/julia/issues/27189
[#27212]: https://github.com/JuliaLang/julia/issues/27212
[#27248]: https://github.com/JuliaLang/julia/issues/27248
8 changes: 4 additions & 4 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,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 @@ -809,7 +809,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 @@ -830,7 +830,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 @@ -891,7 +891,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
3 changes: 3 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1702,6 +1702,9 @@ end

@eval @deprecate $(Symbol("@schedule")) $(Symbol("@async"))

@deprecate atan2(y, x) atan(y, x)


# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
1 change: 0 additions & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ export
asind,
asinh,
atan,
atan2,
atand,
atanh,
big,
Expand Down
9 changes: 4 additions & 5 deletions base/fastmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ const fast_op =
:asin => :asin_fast,
:asinh => :asinh_fast,
:atan => :atan_fast,
:atan2 => :atan2_fast,
:atanh => :atanh_fast,
:cbrt => :cbrt_fast,
:cis => :cis_fast,
Expand Down Expand Up @@ -293,9 +292,9 @@ pow_fast(x::Float32, y::Float32) =
pow_fast(x::Float64, y::Float64) =
ccall(("pow",libm), Float64, (Float64,Float64), x, y)

atan2_fast(x::Float32, y::Float32) =
atan_fast(x::Float32, y::Float32) =
ccall(("atan2f",libm), Float32, (Float32,Float32), x, y)
atan2_fast(x::Float64, y::Float64) =
atan_fast(x::Float64, y::Float64) =
ccall(("atan2",libm), Float64, (Float64,Float64), x, y)

asin_fast(x::FloatTypes) = asin(x)
Expand Down Expand Up @@ -349,7 +348,7 @@ sincos_fast(v) = (sin_fast(v), cos_fast(v))
acos_fast(x::T) where {T<:ComplexTypes} =
convert(T,π)/2 + im*log(im*x + sqrt(1-x*x))
acosh_fast(x::ComplexTypes) = log(x + sqrt(x+1) * sqrt(x-1))
angle_fast(x::ComplexTypes) = atan2(imag(x), real(x))
angle_fast(x::ComplexTypes) = atan(imag(x), real(x))
asin_fast(x::ComplexTypes) = -im*asinh(im*x)
asinh_fast(x::ComplexTypes) = log(x + sqrt(1+x*x))
atan_fast(x::ComplexTypes) = -im*atanh(im*x)
Expand Down Expand Up @@ -387,7 +386,7 @@ for f in (:acos, :acosh, :angle, :asin, :asinh, :atan, :atanh, :cbrt,
end
end

for f in (:^, :atan2, :hypot, :max, :min, :minmax, :log)
for f in (:^, :atan, :hypot, :max, :min, :minmax, :log)
f_fast = fast_op[f]
@eval begin
# fall-back implementation for non-numeric types
Expand Down
26 changes: 14 additions & 12 deletions base/math.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export sin, cos, sincos, tan, sinh, cosh, tanh, asin, acos, atan,
sech, csch, coth, asech, acsch, acoth,
sinpi, cospi, sinc, cosc,
cosd, cotd, cscd, secd, sind, tand,
acosd, acotd, acscd, asecd, asind, atand, atan2,
acosd, acotd, acscd, asecd, asind, atand,
rad2deg, deg2rad,
log, log2, log10, log1p, exponent, exp, exp2, exp10, expm1,
cbrt, sqrt, significand,
Expand Down Expand Up @@ -250,9 +250,17 @@ 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` or `y/x`, respectively.

For one argument, this is the angle in radians between the positive *x*-axis and the point
(1, *y*), returning a value in the interval ``[-\\pi/2, \\pi/2]``.

For two arguments, this is the angle in radians between the positive *x*-axis and the
point (*x*, *y*), returning a value in the interval ``[-\\pi, \\pi]``. This corresponds to a
standard [`atan2`](https://en.wikipedia.org/wiki/Atan2) function.
"""
atan(x::Number)

Expand Down Expand Up @@ -565,14 +573,8 @@ Compute the hypotenuse ``\\sqrt{\\sum x_i^2}`` avoiding overflow and underflow.
"""
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.
"""
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 @@ -1021,7 +1023,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 @@ -191,7 +191,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
1 change: 0 additions & 1 deletion doc/src/base/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ Base.tanh(::Number)
Base.asin(::Number)
Base.acos(::Number)
Base.atan(::Number)
Base.Math.atan2
Base.Math.asind
Base.Math.acosd
Base.Math.atand
Expand Down
7 changes: 3 additions & 4 deletions doc/src/manual/mathematical-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,11 @@ sin cos tan cot sec csc
sinh cosh tanh coth sech csch
asin acos atan acot asec acsc
asinh acosh atanh acoth asech acsch
sinc cosc atan2
sinc cosc
```

These are all single-argument functions, with the exception of [atan2](https://en.wikipedia.org/wiki/Atan2),
which gives the angle in [radians](https://en.wikipedia.org/wiki/Radian) between the *x*-axis
and the point specified by its arguments, interpreted as *x* and *y* coordinates.
These are all single-argument functions, with [`atan`](@ref) also accepting two arguments
corresponding to a traditional [`atan2`](https://en.wikipedia.org/wiki/Atan2) function.

Additionally, [`sinpi(x)`](@ref) and [`cospi(x)`](@ref) are provided for more accurate computations
of [`sin(pi*x)`](@ref) and [`cos(pi*x)`](@ref) respectively.
Expand Down
24 changes: 12 additions & 12 deletions test/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ let x = [1, 3.2, 4.7],
@test sin.(α) == broadcast(sin, α)
@test sin.(3.2) == broadcast(sin, 3.2) == sin(3.2)
@test factorial.(3) == broadcast(factorial, 3)
@test atan2.(x, y) == broadcast(atan2, x, y)
@test atan2.(x, y') == broadcast(atan2, x, y')
@test atan2.(x, α) == broadcast(atan2, x, α)
@test atan2.(α, y') == broadcast(atan2, α, y')
@test atan.(x, y) == broadcast(atan, x, y)
@test atan.(x, y') == broadcast(atan, x, y')
@test atan.(x, α) == broadcast(atan, x, α)
@test atan.(α, y') == broadcast(atan, α, y')
end

# issue 14725
Expand Down Expand Up @@ -215,13 +215,13 @@ end
# PR #17300: loop fusion
@test (x->x+1).((x->x+2).((x->x+3).(1:10))) == 7:16
let A = [sqrt(i)+j for i = 1:3, j=1:4]
@test atan2.(log.(A), sum(A, dims=1)) == broadcast(atan2, broadcast(log, A), sum(A, dims=1))
@test atan.(log.(A), sum(A, dims=1)) == broadcast(atan, broadcast(log, A), sum(A, dims=1))
end
let x = sin.(1:10)
@test atan2.((x->x+1).(x), (x->x+2).(x)) == broadcast(atan2, x.+1, x.+2)
@test sin.(atan2.([x.+1,x.+2]...)) == sin.(atan2.(x.+1 ,x.+2)) == @. sin(atan2(x+1,x+2))
@test sin.(atan2.(x, 3.7)) == broadcast(x -> sin(atan2(x,3.7)), x)
@test atan2.(x, 3.7) == broadcast(x -> atan2(x,3.7), x) == broadcast(atan2, x, 3.7)
@test atan.((x->x+1).(x), (x->x+2).(x)) == broadcast(atan, x.+1, x.+2)
@test sin.(atan.([x.+1,x.+2]...)) == sin.(atan.(x.+1 ,x.+2)) == @. sin(atan(x+1,x+2))
@test sin.(atan.(x, 3.7)) == broadcast(x -> sin(atan(x,3.7)), x)
@test atan.(x, 3.7) == broadcast(x -> atan(x,3.7), x) == broadcast(atan, x, 3.7)
end
# Use side effects to check for loop fusion.
let g = Int[]
Expand All @@ -235,11 +235,11 @@ end
# fusion with splatted args:
let x = sin.(1:10), a = [x]
@test cos.(x) == cos.(a...)
@test atan2.(x,x) == atan2.(a..., a...) == atan2.([x, x]...)
@test atan2.(x, cos.(x)) == atan2.(a..., cos.(x)) == broadcast(atan2, x, cos.(a...)) == broadcast(atan2, a..., cos.(a...))
@test atan.(x,x) == atan.(a..., a...) == atan.([x, x]...)
@test atan.(x, cos.(x)) == atan.(a..., cos.(x)) == broadcast(atan, x, cos.(a...)) == broadcast(atan, a..., cos.(a...))
@test ((args...)->cos(args[1])).(x) == cos.(x) == ((y,args...)->cos(y)).(x)
end
@test atan2.(3, 4) == atan2(3, 4) == (() -> atan2(3, 4)).()
@test atan.(3, 4) == atan(3, 4) == (() -> atan(3, 4)).()
# fusion with keyword args:
let x = [1:4;]
f17300kw(x; y=0) = x + y
Expand Down
2 changes: 1 addition & 1 deletion test/fastmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ end
end
end
for f in (:+, :-, :*, :/, :%, :(==), :!=, :<, :<=, :>, :>=, :^,
:atan2, :hypot, :max, :min, :log)
:atan, :hypot, :max, :min, :log)
@eval begin
@test @fastmath($f($half, $third)) ≈ $f($half, $third)
@test @fastmath($f($third, $half)) ≈ $f($third, $half)
Expand Down
Loading