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.
1 2 3 4 5 6 7 8 9 10 11 12
numeric or complex vectors.
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
tanpi(x) are accurate
x values which are multiples of a half.
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. (
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.)
NaN. Similarly for other inputs
with fractional part
For the inverse trigonometric functions, branch cuts are defined as in Abramowitz and Stegun, figure 4.4, page 79.
acos, there are two cuts, both along
the real axis: (-Inf, -1] and
atan there are two cuts, both along the pure imaginary
axis: (-1i*Inf, -1i] and
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
are not yet implemented, and they are a ‘future direction’ of
ISO/IEC TS 18661-4.
atan2 are S4 generic functions: methods can be defined
for them individually or via the
Math group generic.
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
tanpi the C11 extension
ISO/IEC TS 18661-4:2015 (draft at
1 2 3 4 5 6 7
We want your feedback!
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.