All rights reserved. The Berkeley software License Agreement
specifies the terms and conditions for redistribution.
@(#)sin.3 6.6 (Berkeley) 05/12/86
#include <math.h>double sin(x) double x;
double cos(x) double x;
double tan(x) double x;
double asin(x) double x;
double acos(x) double x;
double atan(x) double x;
double atan2(y,x) double y,x;
Asin returns the arc sine in the range
i /2 - to
i /2.
Acos returns the arc cosine in the range 0 to
i.
Atan returns the arc tangent in the range
i /2 - to
i /2.
On a VAX,
atan2(y,x) := atan(y/x) if x > 0, sign(y)\(**(pi - atan(|y/x|)) if x < 0, 0 if x = y = 0, or sign(y)\(**pi/2 if x = 0 != y. \} atan2(y,x) := atan(y/x) if x > 0, sign(y)\(**(\(*p - atan(|y/x|)) if x < 0, 0 if x = y = 0, or sign(y)\(**\(*p/2 if x = 0 \(!= y. \}
r := hypot(x,y); ... := sqrt(x\(**x+y\(**y) theta := atan2(y,x). r := hypot(x,y); ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d) \(*h := atan2(y,x).
i , \(+- for instance. In general the formulas above are equivalent to these:
r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x); r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x);if x > 0 then theta := 2\(**atan(y/(r+x)) if x > 0 then \(*h := 2\(**atan(y/(r+x)) else theta := 2\(**atan((r-x)/y); else \(*h := 2\(**atan((r-x)/y);
i /4 that would otherwise have to be obtained by taking limits.
i " = 3.14159 26535 89793 23846 26433 ... ." Let "trig" stand for one of "sin", "cos" or "tan". Then the expression "trig(x)" in a program actually produces an approximation to
i /P), trig(x\(** and "atrig(x)" approximates
i )\(**atrig(x). (P/ The approximations are close, within 0.9 \*(ups for sin, cos and atan, within 2.2 \*(ups for tan, asin, acos and atan2 on a VAX. Moreover,
i "P = " in the codes that run on a VAX. In the codes that run on other machines, P differs from
i by a fraction of an \*(up; the difference matters only if the argument x is huge, and even then the difference is likely to be swamped by the uncertainty in x. Besides, every trigonometric identity that does not involve
i explicitly is satisfied equally well regardless of whether
i . "P = " For instance, sin(x)**2+cos(x)**2\0=\01 sin\u\s62\s10\d(x)+cos\u\s62\s10\d(x)\0=\01 and sin(2x)\0=\02\|sin(x)cos(x) to within a few \*(ups no matter how big x may be. Therefore the difference between P and
i is most unlikely to affect scientific and engineering computations.