Compute sin(x)
and cos(x)
with x
in degrees
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=wp), | intent(in) | :: | x | |||
real(kind=wp), | intent(out) | :: | sinx | |||
real(kind=wp), | intent(out) | :: | cosx |
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