TRIG(3M) — MATHEMATICAL LIBRARY
NAME
sin, cos, tan, asin, acos, atan, atan2 − trigonometric functions
SYNOPSIS
#include <math.h>
double sin(double x);
double cos(double x);
double tan(double x);
double asin(double x);
double acos(double x);
double atan(double x);
double atan2(double y, double x);
void sincos(double x, double ∗s, double ∗c);
double sind(double x);
double cosd(double x);
double tand(double x);
double asind(double x);
double acosd(double x);
double atand(double x);
double atan2d(double y, double x);
void sincosd(double x, double ∗s, double ∗c);
double sinp(double x);
double cosp(double x);
double tanp(double x);
double asinp(double x);
double acosp(double x);
double atanp(double x);
void sincosp(double x, double ∗s, double ∗c);
double sinpi(double x);
double cospi(double x);
double tanpi(double x);
double asinpi(double x);
double acospi(double x);
double atanpi(double x);
double atan2pi(double y, double x);
void sincospi(double x, double ∗s, double ∗c);
DESCRIPTION
sin(x), cos(x), sincos(x,s,c) and tan(x) return trigonometric functions of radian arguments. Trigonometric argument reduction is discussed in the Floating-Point Programmer’s Guide. Note that sincos(x,s,c) allows simultaneous computation of ∗s:=sin(x) and ∗c:=cos(x).
asin(x) returns the arc sine of x in the range −π/2 to π/2.
acos(x) returns the arc cosine of x in the range 0 to π.
atan(x) returns the arc tangent of x in the range −π/2 to π/2.
atan2(y,x) and hypot(x,y) (see hypot(3M)) convert rectangular coordinates (x,y) to polar (r,θ); atan2(y,x) computes θ, the argument or phase, by computing an arc tangent of y/x in the range −π to π. atan2(0.0,0.0) is 0.0, in conformance with SVID.
sind(x), cosd(x), and tand(x) return trigonometric functions of degree arguments. sind(x):= sin(x∗π/180). The corresponding inverse functions compute asind(x):= asin(x)∗180/π. Similarly atan2d(y,x):= atan2(y,x)∗180/π.
sinpi(x), cospi(x), and tanpi(x) avoid range-reduction issues because their definition sinpi(x):= sin(π∗x) permits range reduction that is fast and exact for all x. The corresponding inverse functions compute asinpi(x):= asin(x)/π. Similarly atan2pi(y,x):= atan2(y,x)/π.
sinp(x), cosp(x), and tanp(x) use PI/2, the double precision approximation to π/2, in the argument reduction step to reduce arguments exceeding PI/4 in magnitude to the range −PI/4 to PI/4 . The argument reduction step is accomplished by the fmod function; thus it is much faster than using the true value of π. The relation between sinp and sin is sinp(x):= sin(x∗π/PI). The corresponding inverse functions asinp(x):= asin(x)∗PI/π. Since PI/π is close to 1, we simply return asin(x). The same applies to acosp(x) and atanp(x).
DIAGNOSTICS
These functions handle exceptional arguments in the spirit of ANSI/IEEE Std 754-1985 and in conformance with SVID. sin(±∞), cos(±∞) and tan(±∞) return NaN; asin(x) or acos(x) with |x|>1, return 0.0; sinpi(x) et. al. are similar. In addition, asin(x), acos(x), and atan2(y,x) may also set errno and call matherr(3M).
SEE ALSO
Sun Release 4.1 — Last change: 25 October 1991