Skip to content

Proposal: Add cisd function for argument in degrees #60445

@jondeuce

Description

@jondeuce

I found myself needing to define a convenience function cisd(theta) = cis(deg2rad(theta)), and given that Base already exports sincosd, cosd, sind, and tand, it seems reasonable to add cisd as well.

A proposed implementation that mirrors the cispi implementation could be:

"""
    cisd(x)

More accurate method for `cis(deg2rad(x))` (especially for large `x`).

See also [`cis`](@ref), [`cispi`](@ref), [`sincosd`](@ref), [`exp`](@ref), [`angle`](@ref).

# Examples
julia> cisd(180)
-1.0 + 0.0im

julia> cisd(45) ≈ 1/sqrt(2) + im/sqrt(2)
true
"""
function cisd end
function cisd(theta::Real)
    s, c = sincosd(theta)
    Complex(c, s)
end

function cisd(z::Complex)
    v = exp(-deg2rad(imag(z)))
    s, c = sincosd(real(z))
    Complex(v * c, v * s)
end

I'm happy to open a PR with some tests if this seems reasonable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexComplex numbersmathsMathematical functionstriageThis should be discussed on a triage call

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions