# Trig: Trigonometric Functions

Description Usage Arguments Details Value Complex values S4 methods References Examples

## Description

These functions give the obvious trigonometric functions. They respectively compute the cosine, sine, tangent, arc-cosine, arc-sine, arc-tangent, and the two-argument arc-tangent.

`cospi(x)`, `sinpi(x)`, and `tanpi(x)`, compute `cos(pi*x)`, `sin(pi*x)`, and `tan(pi*x)`.

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11 12``` ```cos(x) sin(x) tan(x) acos(x) asin(x) atan(x) atan2(y, x) cospi(x) sinpi(x) tanpi(x) ```

## Arguments

 `x, y` numeric or complex vectors.

## Details

The arc-tangent of two arguments `atan2(y, x)` returns the angle between the x-axis and the vector from the origin to (x, y), i.e., for positive arguments `atan2(y, x) == atan(y/x)`.

Angles are in radians, not degrees, for the standard versions (i.e., a right angle is π/2), and in ‘half-rotations’ for `cospi` etc.

`cospi(x)`, `sinpi(x)`, and `tanpi(x)` are accurate for `x` values which are multiples of a half.

All except `atan2` are internal generic primitive functions: methods can be defined for them individually or via the `Math` group generic.

These are all wrappers to system calls of the same name (with prefix `c` for complex arguments) where available. (`cospi`, `sinpi`, and `tanpi` are part of a C11 extension and provided by e.g. macOS and Solaris: where not yet available call to `cos` etc are used, with special cases for multiples of a half.)

## Value

`tanpi(0.5)` is `NaN`. Similarly for other inputs with fractional part `0.5`.

## Complex values

For the inverse trigonometric functions, branch cuts are defined as in Abramowitz and Stegun, figure 4.4, page 79.

For `asin` and `acos`, there are two cuts, both along the real axis: (-Inf, -1] and [1, Inf).

For `atan` there are two cuts, both along the pure imaginary axis: (-1i*Inf, -1i] and [1i, 1i*Inf).

The behaviour actually on the cuts follows the C99 standard which requires continuity coming round the endpoint in a counter-clockwise direction.

Complex arguments for `cospi`, `sinpi`, and `tanpi` are not yet implemented, and they are a ‘future direction’ of ISO/IEC TS 18661-4.

## S4 methods

All except `atan2` are S4 generic functions: methods can be defined for them individually or via the `Math` group generic.

## References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.

Abramowitz, M. and Stegun, I. A. (1972). Handbook of Mathematical Functions. New York: Dover.
Chapter 4. Elementary Transcendental Functions: Logarithmic, Exponential, Circular and Hyperbolic Functions

For `cospi`, `sinpi`, and `tanpi` the C11 extension ISO/IEC TS 18661-4:2015 (draft at http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1950.pdf).

## Examples

 ```1 2 3 4 5 6 7``` ```x <- seq(-3, 7, by = 1/8) tx <- cbind(x, cos(pi*x), cospi(x), sin(pi*x), sinpi(x), tan(pi*x), tanpi(x), deparse.level=2) op <- options(digits = 4, width = 90) # for nice formatting head(tx) tx[ (x %% 1) %in% c(0, 0.5) ,] options(op) ```