sincosd Subroutine

public pure subroutine sincosd(x, sinx, cosx)

Compute sin(x) and cos(x) with x in degrees

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: x
real(kind=wp), intent(out) :: sinx
real(kind=wp), intent(out) :: cosx

Source Code

    pure subroutine sincosd(x, sinx, cosx)

    real(wp),intent(in) :: x
    real(wp),intent(out) :: sinx, cosx

    real(wp) :: r, s, c
    integer :: q

    r = mod(x, 360.0_wp)
    q = nint(r / 90.0_wp)
    r = (r - 90.0_wp * q) * degree
    s = sin(r)
    c = cos(r)
    q = mod(q + 4, 4)
    select case (q)
    case(0)
        sinx =  s
        cosx =  c
    case(1)
        sinx =  c
        cosx = -s
    case(2)
        sinx = -s
        cosx = -c
    case(3)
        sinx = -c
        cosx =  s
    end select

    if (sinx == 0.0_wp) then
        sinx = sign(sinx, x)
    end if
    cosx = 0.0_wp + cosx

    end subroutine sincosd