tan

Compute the tangent of x expressed in radians.

Base.tanFunction
tan(x::T) where {T <: Number} -> float(T)

Compute tangent of x, where x is in radians.

Throw a DomainError if isinf(x), return a T(NaN) if isnan(x).

See also tanh.

source
tan(A::AbstractMatrix)

Compute the matrix tangent of a square matrix A.

If A is symmetric or Hermitian, its eigendecomposition (eigen) is used to compute the tangent. Otherwise, the tangent is determined by calling exp.

Examples

julia> tan(fill(1.0, (2,2)))
2×2 Matrix{Float64}:
 -1.09252  -1.09252
 -1.09252  -1.09252

Methods

julia> methods(tan, (Any,), [Base, Base.Math, Base.MathConstants, Base.MPFR])# 8 methods for generic function "tan" from Base:
 [1] tan(a::ComplexF16)
     @ math.jl:1527
 [2] tan(::Missing)
     @ math.jl:1548
 [3] tan(x::BigFloat)
     @ mpfr.jl:946
 [4] tan(a::Float16)
     @ math.jl:1526
 [5] tan(::Irrational{:π})
     @ mathconstants.jl:149
 [6] tan(z::Complex)
     @ complex.jl:932
 [7] tan(x::T) where T<:Union{Float32, Float64}
     @ special/trig.jl:218
 [8] tan(x::Real)
     @ math.jl:1543

Examples

julia> using UnicodePlots
julia> lineplot(-2π, 2π, tan, xlim=(-7, 7), ylim=(-4, 4)) ┌────────────────────────────────────────┐ 4 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ tan(x) ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⢰⠃⠀⠀⠀⠀⠀⠀⠀⢰⠃⠀⠀⠀⠀⠀⡇⠀⢰⠁⠀⠀⠀⠀⠀⠀⠀⢰⠁⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⢀⠜⠀⠀⠀⠀⠀⠀⠀⢀⠜⠀⠀⠀⠀⠀⠀⠀⣇⠎⠀⠀⠀⠀⠀⠀⠀⢀⠎⠀⠀⠀⠀⠀⠀⠀⠀⠀ f(x) ⠤⠤⠤⠤⠤⠤⠤⠤⠤⡤⠮⠤⠤⠤⠤⠤⠤⠤⡤⡯⠤⠤⠤⠤⠤⠤⠤⡤⠮⠤⠤⠤⠤⠤⠤⠤⠤⠤ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⡴⠁⠀⠀⠀⠀⠀⠀⠀⡴⠁⡇⠀⠀⠀⠀⠀⠀⡔⠁⠀⠀⠀⠀⠀⠀⠀⡔⠁⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⢀⠇⠀⠀⠀⠀⠀⠀⠀⢀⠇⠀⠀⡇⠀⠀⠀⠀⢠⠃⠀⠀⠀⠀⠀⠀⠀⢠⠃⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ -4 ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ └────────────────────────────────────────┘-7⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀7⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀x⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

Real Numbers

julia> tan(0)
0.0

julia> tan(-0.0)
-0.0

julia> tan(pi/4)
0.9999999999999999

julia> tan(pi/2)
1.633123935319537e16

julia> tan(pi)
0.0

Complex

julia> tan(0+0im)
0.0 - 0.0im

Tips

See Also

Extended Inputs

Matrix

With Array like input:

julia> methods(tan, (Any,), [LinearAlgebra])# 5 methods for generic function "tan" from Base:
 [1] tan(D::Diagonal)
     @ /opt/hostedtoolcache/julia/1.12.2/x64/share/julia/stdlib/v1.12/LinearAlgebra/src/diagonal.jl:879
 [2] tan(J::UniformScaling)
     @ /opt/hostedtoolcache/julia/1.12.2/x64/share/julia/stdlib/v1.12/LinearAlgebra/src/uniformscaling.jl:176
 [3] tan(A::Hermitian{var"#s4811", S} where {var"#s4811"<:Complex, S<:(AbstractMatrix{<:var"#s4811"})})
     @ /opt/hostedtoolcache/julia/1.12.2/x64/share/julia/stdlib/v1.12/LinearAlgebra/src/symmetric.jl:898
 [4] tan(A::Union{Hermitian{T, S} where S, SymTridiagonal{T, V} where V<:AbstractVector{T}, Symmetric{T, S} where S} where T<:Real)
     @ /opt/hostedtoolcache/julia/1.12.2/x64/share/julia/stdlib/v1.12/LinearAlgebra/src/symmetric.jl:894
 [5] tan(A::AbstractMatrix)
     @ /opt/hostedtoolcache/julia/1.12.2/x64/share/julia/stdlib/v1.12/LinearAlgebra/src/dense.jl:1255

Tech Notes

  • tan(::Real): by pure julia
  • tan(::BigFloat): by MPFR

Version History

Introduced in Julia v1.0 (2018)