From 2794281ba8b752c7cfd7132ff584f43f4de200e3 Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Thu, 24 May 2018 16:13:15 -0700 Subject: [PATCH 1/2] atan2 -> atan --- NEWS.md | 3 + base/complex.jl | 8 +-- base/deprecated.jl | 3 + base/exports.jl | 1 - base/fastmath.jl | 9 ++- base/math.jl | 26 +++---- base/mpfr.jl | 4 +- base/number.jl | 2 +- base/special/trig.jl | 2 +- doc/src/base/math.md | 1 - doc/src/manual/mathematical-operations.md | 7 +- test/broadcast.jl | 24 +++---- test/fastmath.jl | 2 +- test/math.jl | 88 +++++++++++------------ test/mpfr.jl | 4 +- test/numbers.jl | 2 +- 16 files changed, 95 insertions(+), 91 deletions(-) diff --git a/NEWS.md b/NEWS.md index 330c919a1fbe7..76216c3a0a918 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 `atan` function ([#27248]). + Command-line option changes --------------------------- @@ -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 diff --git a/base/complex.jl b/base/complex.jl index 4969eea3d24b2..d074e13bcbd12 100644 --- a/base/complex.jl +++ b/base/complex.jl @@ -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 @@ -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 @@ -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(ξ,η) @@ -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 diff --git a/base/deprecated.jl b/base/deprecated.jl index dbb6438563dc7..9fd11b0a0ce0e 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -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 diff --git a/base/exports.jl b/base/exports.jl index cfe865295c287..d5d9cb61f540b 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -212,7 +212,6 @@ export asind, asinh, atan, - atan2, atand, atanh, big, diff --git a/base/fastmath.jl b/base/fastmath.jl index 4f77f584bee79..09d51f3b068cc 100644 --- a/base/fastmath.jl +++ b/base/fastmath.jl @@ -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, @@ -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) @@ -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) @@ -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 diff --git a/base/math.jl b/base/math.jl index 551d370b215d3..635c138317dcd 100644 --- a/base/math.jl +++ b/base/math.jl @@ -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, @@ -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) @@ -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)) @@ -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 diff --git a/base/mpfr.jl b/base/mpfr.jl index f3b68d35bf421..e7f277dbad784 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -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 @@ -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 diff --git a/base/number.jl b/base/number.jl index 89cec5169e870..c2a6d8501940a 100644 --- a/base/number.jl +++ b/base/number.jl @@ -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) diff --git a/base/special/trig.jl b/base/special/trig.jl index eda5e08bf30df..33973effb8aa7 100644 --- a/base/special/trig.jl +++ b/base/special/trig.jl @@ -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): diff --git a/doc/src/base/math.md b/doc/src/base/math.md index bc1312708da11..1359b11d34c9d 100644 --- a/doc/src/base/math.md +++ b/doc/src/base/math.md @@ -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 diff --git a/doc/src/manual/mathematical-operations.md b/doc/src/manual/mathematical-operations.md index 1e8cccab8d9f1..aae4ce14b7b58 100644 --- a/doc/src/manual/mathematical-operations.md +++ b/doc/src/manual/mathematical-operations.md @@ -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. diff --git a/test/broadcast.jl b/test/broadcast.jl index e664bae7e22df..28fe64e87cb8a 100644 --- a/test/broadcast.jl +++ b/test/broadcast.jl @@ -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 @@ -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[] @@ -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 diff --git a/test/fastmath.jl b/test/fastmath.jl index a8e1822efcf7b..dba77a6d9e5a7 100644 --- a/test/fastmath.jl +++ b/test/fastmath.jl @@ -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) diff --git a/test/math.jl b/test/math.jl index c537b456caa47..1fa07f266a3f8 100644 --- a/test/math.jl +++ b/test/math.jl @@ -143,7 +143,7 @@ end @test asin(x) ≈ asin(big(x)) @test asinh(x) ≈ asinh(big(x)) @test atan(x) ≈ atan(big(x)) - @test atan2(x,y) ≈ atan2(big(x),big(y)) + @test atan(x,y) ≈ atan(big(x),big(y)) @test atanh(x) ≈ atanh(big(x)) @test cbrt(x) ≈ cbrt(big(x)) @test cos(x) ≈ cos(big(x)) @@ -172,7 +172,7 @@ end @test isequal(acosh(T(1)), T(0)) @test asin(T(1)) ≈ T(pi)/2 atol=eps(T) @test atan(T(1)) ≈ T(pi)/4 atol=eps(T) - @test atan2(T(1),T(1)) ≈ T(pi)/4 atol=eps(T) + @test atan(T(1),T(1)) ≈ T(pi)/4 atol=eps(T) @test isequal(cbrt(T(0)), T(0)) @test isequal(cbrt(T(1)), T(1)) @test isequal(cbrt(T(1000000000)), T(1000)) @@ -211,7 +211,7 @@ end @test cbrt(x^3) ≈ x @test asinh(sinh(x)) ≈ x @test atan(tan(x)) ≈ x - @test atan2(x,y) ≈ atan(x/y) + @test atan(x,y) ≈ atan(x/y) @test atanh(tanh(x)) ≈ x @test cos(acos(x)) ≈ x @test cosh(acosh(1+x)) ≈ 1+x @@ -612,7 +612,7 @@ end @testset "vectorization of 2-arg functions" begin binary_math_functions = [ - copysign, flipsign, log, atan2, hypot, max, min, + copysign, flipsign, log, atan, hypot, max, min, beta, lbeta, ] @testset "$f" for f in binary_math_functions @@ -788,58 +788,58 @@ end @test atan(1.7581305072934137) ≈ 1.053644580517088 end end -@testset "atan2" begin +@testset "atan" begin for T in (Float32, Float64) - @test isnan_type(T, atan2(T(NaN), T(NaN))) - @test isnan_type(T, atan2(T(NaN), T(0.1))) - @test isnan_type(T, atan2(T(0.1), T(NaN))) + @test isnan_type(T, atan(T(NaN), T(NaN))) + @test isnan_type(T, atan(T(NaN), T(0.1))) + @test isnan_type(T, atan(T(0.1), T(NaN))) r = T(randn()) absr = abs(r) # y zero - @test atan2(T(r), one(T)) === atan(T(r)) - @test atan2(zero(T), absr) === zero(T) - @test atan2(-zero(T), absr) === -zero(T) - @test atan2(zero(T), -absr) === T(pi) - @test atan2(-zero(T), -absr) === -T(pi) + @test atan(T(r), one(T)) === atan(T(r)) + @test atan(zero(T), absr) === zero(T) + @test atan(-zero(T), absr) === -zero(T) + @test atan(zero(T), -absr) === T(pi) + @test atan(-zero(T), -absr) === -T(pi) # x zero and y not zero - @test atan2(one(T), zero(T)) === T(pi)/2 - @test atan2(-one(T), zero(T)) === -T(pi)/2 + @test atan(one(T), zero(T)) === T(pi)/2 + @test atan(-one(T), zero(T)) === -T(pi)/2 # isinf(x) == true && isinf(y) == true - @test atan2(T(Inf), T(Inf)) === T(pi)/4 # m == 0 (see atan2 code) - @test atan2(-T(Inf), T(Inf)) === -T(pi)/4 # m == 1 - @test atan2(T(Inf), -T(Inf)) === 3*T(pi)/4 # m == 2 - @test atan2(-T(Inf), -T(Inf)) === -3*T(pi)/4 # m == 3 + @test atan(T(Inf), T(Inf)) === T(pi)/4 # m == 0 (see atan code) + @test atan(-T(Inf), T(Inf)) === -T(pi)/4 # m == 1 + @test atan(T(Inf), -T(Inf)) === 3*T(pi)/4 # m == 2 + @test atan(-T(Inf), -T(Inf)) === -3*T(pi)/4 # m == 3 # isinf(x) == true && isinf(y) == false - @test atan2(absr, T(Inf)) === zero(T) # m == 0 - @test atan2(-absr, T(Inf)) === -zero(T) # m == 1 - @test atan2(absr, -T(Inf)) === T(pi) # m == 2 - @test atan2(-absr, -T(Inf)) === -T(pi) # m == 3 + @test atan(absr, T(Inf)) === zero(T) # m == 0 + @test atan(-absr, T(Inf)) === -zero(T) # m == 1 + @test atan(absr, -T(Inf)) === T(pi) # m == 2 + @test atan(-absr, -T(Inf)) === -T(pi) # m == 3 # isinf(y) == true && isinf(x) == false - @test atan2(T(Inf), absr) === T(pi)/2 - @test atan2(-T(Inf), absr) === -T(pi)/2 - @test atan2(T(Inf), -absr) === T(pi)/2 - @test atan2(-T(Inf), -absr) === -T(pi)/2 + @test atan(T(Inf), absr) === T(pi)/2 + @test atan(-T(Inf), absr) === -T(pi)/2 + @test atan(T(Inf), -absr) === T(pi)/2 + @test atan(-T(Inf), -absr) === -T(pi)/2 # |y/x| above high threshold atanpi = T(1.5707963267948966) - @test atan2(T(2.0^61), T(1.0)) === atanpi # m==0 - @test atan2(-T(2.0^61), T(1.0)) === -atanpi # m==1 - @test atan2(T(2.0^61), -T(1.0)) === atanpi # m==2 - @test atan2(-T(2.0^61), -T(1.0)) === -atanpi # m==3 - @test atan2(-T(Inf), -absr) === -T(pi)/2 + @test atan(T(2.0^61), T(1.0)) === atanpi # m==0 + @test atan(-T(2.0^61), T(1.0)) === -atanpi # m==1 + @test atan(T(2.0^61), -T(1.0)) === atanpi # m==2 + @test atan(-T(2.0^61), -T(1.0)) === -atanpi # m==3 + @test atan(-T(Inf), -absr) === -T(pi)/2 # |y|/x between 0 and low threshold - @test atan2(T(2.0^-61), -T(1.0)) === T(pi) # m==2 - @test atan2(-T(2.0^-61), -T(1.0)) === -T(pi) # m==3 + @test atan(T(2.0^-61), -T(1.0)) === T(pi) # m==2 + @test atan(-T(2.0^-61), -T(1.0)) === -T(pi) # m==3 # y/x is "safe" ("arbitrary values", just need to hit the branch) - _ATAN2_PI_LO(::Type{Float32}) = -8.7422776573f-08 - _ATAN2_PI_LO(::Type{Float64}) = 1.2246467991473531772E-16 - @test atan2(T(5.0), T(2.5)) === atan(abs(T(5.0)/T(2.5))) - @test atan2(-T(5.0), T(2.5)) === -atan(abs(-T(5.0)/T(2.5))) - @test atan2(T(5.0), -T(2.5)) === T(pi)-(atan(abs(T(5.0)/-T(2.5)))-_ATAN2_PI_LO(T)) - @test atan2(-T(5.0), -T(2.5)) === -(T(pi)-atan(abs(-T(5.0)/-T(2.5)))-_ATAN2_PI_LO(T)) - @test atan2(T(1235.2341234), T(2.5)) === atan(abs(T(1235.2341234)/T(2.5))) - @test atan2(-T(1235.2341234), T(2.5)) === -atan(abs(-T(1235.2341234)/T(2.5))) - @test atan2(T(1235.2341234), -T(2.5)) === T(pi)-(atan(abs(T(1235.2341234)/-T(2.5)))-_ATAN2_PI_LO(T)) - @test atan2(-T(1235.2341234), -T(2.5)) === -(T(pi)-(atan(abs(-T(1235.2341234)/T(2.5)))-_ATAN2_PI_LO(T))) + _ATAN_PI_LO(::Type{Float32}) = -8.7422776573f-08 + _ATAN_PI_LO(::Type{Float64}) = 1.2246467991473531772E-16 + @test atan(T(5.0), T(2.5)) === atan(abs(T(5.0)/T(2.5))) + @test atan(-T(5.0), T(2.5)) === -atan(abs(-T(5.0)/T(2.5))) + @test atan(T(5.0), -T(2.5)) === T(pi)-(atan(abs(T(5.0)/-T(2.5)))-_ATAN_PI_LO(T)) + @test atan(-T(5.0), -T(2.5)) === -(T(pi)-atan(abs(-T(5.0)/-T(2.5)))-_ATAN_PI_LO(T)) + @test atan(T(1235.2341234), T(2.5)) === atan(abs(T(1235.2341234)/T(2.5))) + @test atan(-T(1235.2341234), T(2.5)) === -atan(abs(-T(1235.2341234)/T(2.5))) + @test atan(T(1235.2341234), -T(2.5)) === T(pi)-(atan(abs(T(1235.2341234)/-T(2.5)))-_ATAN_PI_LO(T)) + @test atan(-T(1235.2341234), -T(2.5)) === -(T(pi)-(atan(abs(-T(1235.2341234)/T(2.5)))-_ATAN_PI_LO(T))) end end diff --git a/test/mpfr.jl b/test/mpfr.jl index 7ce5f577f9bb2..fab600887ddac 100644 --- a/test/mpfr.jl +++ b/test/mpfr.jl @@ -696,9 +696,9 @@ end # hypot @test hypot(BigFloat(3), BigFloat(4)) == 5 - # atan2 + # atan setprecision(53) do - @test atan2(12,2) == atan2(BigFloat(12), BigFloat(2)) + @test atan(12,2) == atan(BigFloat(12), BigFloat(2)) end end @testset "ldexp" begin diff --git a/test/numbers.jl b/test/numbers.jl index b4a8910d365d5..8e6d6ef95914a 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -2214,7 +2214,7 @@ end end end end -@testset "angle(z::Real) = atan2(zero(z), z)" begin +@testset "angle(z::Real) = atan(zero(z), z)" begin #function only returns two values, depending on sign @test angle(10) == 0.0 @test angle(-10) == 3.141592653589793 From 1010ae0704a5c4e12d9254ccec45657c39488117 Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Wed, 6 Jun 2018 14:45:05 -0700 Subject: [PATCH 2/2] Update NEWS.md --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 76216c3a0a918..905888015b1f1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1256,7 +1256,7 @@ Deprecated or removed * `setrounding` has been deprecated for `Float32` and `Float64`, as the behaviour was too unreliable ([#26935]). - * `atan2` is now a 2-argument `atan` function ([#27248]). + * `atan2` is now a 2-argument method of `atan` ([#27248]). Command-line option changes ---------------------------