Annotation of 43BSDTahoe/man/man3/sin.3, revision 1.1.1.1

1.1       root        1: .\" Copyright (c) 1985 Regents of the University of California.
                      2: .\" All rights reserved.  The Berkeley software License Agreement
                      3: .\" specifies the terms and conditions for redistribution.
                      4: .\"
                      5: .\"    @(#)sin.3m      6.6 (Berkeley) 5/12/86
                      6: .\"
                      7: .TH SIN 3M  "May 12, 1986"
                      8: .UC 4
                      9: .de Pi         \" PI stuff sign
                     10: .if n \\
                     11: \\$2pi\\$1
                     12: .if t \\
                     13: \\$2\\(*p\\$1
                     14: ..
                     15: .ds up \fIulp\fR
                     16: .SH NAME
                     17: sin, cos, tan, asin, acos, atan, atan2 \- trigonometric functions
                     18: and their inverses
                     19: .SH SYNOPSIS
                     20: .nf
                     21: .B #include <math.h>
                     22: .PP
                     23: .B double sin(x)
                     24: .B double x;
                     25: .PP
                     26: .B double cos(x)
                     27: .B double x;
                     28: .PP
                     29: .B double tan(x)
                     30: .B double x;
                     31: .PP
                     32: .B double asin(x)
                     33: .B double x;
                     34: .PP
                     35: .B double acos(x)
                     36: .B double x;
                     37: .PP
                     38: .B double atan(x)
                     39: .B double x;
                     40: .PP
                     41: .B double atan2(y,x)
                     42: .B double y,x;
                     43: .fi
                     44: .SH DESCRIPTION
                     45: Sin, cos and tan
                     46: return trigonometric functions of radian arguments x.
                     47: .PP
                     48: Asin returns the arc sine in the range 
                     49: .Pi /2 \-
                     50: to
                     51: .Pi /2.
                     52: .PP
                     53: Acos returns the arc cosine in the range 0 to
                     54: .Pi.
                     55: .PP
                     56: Atan returns the arc tangent in the range
                     57: .Pi /2 \-
                     58: to
                     59: .Pi /2.
                     60: .PP
                     61: On a VAX,
                     62: .nf
                     63: .if n \{\
                     64: .ta \w'atan2(y,x) := 'u+2n +\w'sign(y)\(**(pi \- atan(|y/x|))'u+2n
                     65: atan2(y,x) :=  atan(y/x)       if x > 0,
                     66:        sign(y)\(**(pi \- atan(|y/x|))  if x < 0,
                     67:        0       if x = y = 0, or
                     68:        sign(y)\(**pi/2 if x = 0 != y.  \}
                     69: .if t \{\
                     70: .ta \w'atan2(y,x) := 'u+2n +\w'sign(y)\(**(\(*p \- atan(|y/x|))'u+2n
                     71: atan2(y,x) :=  atan(y/x)       if x > 0,
                     72:        sign(y)\(**(\(*p \- atan(|y/x|))        if x < 0,
                     73:        0       if x = y = 0, or
                     74:        sign(y)\(**\(*p/2       if x = 0 \(!= y.  \}
                     75: .ta
                     76: .fi
                     77: .SH DIAGNOSTICS
                     78: On a VAX, if |x| > 1 then asin(x) and acos(x)
                     79: will return reserved operands and \fIerrno\fR will be set to EDOM.
                     80: .SH NOTES
                     81: Atan2 defines atan2(0,0) = 0 on a VAX despite that previously
                     82: atan2(0,0) may have generated an error message.
                     83: The reasons for assigning a value to atan2(0,0) are these:
                     84: .IP (1) \w'\0\0\0\0'u
                     85: Programs that test arguments to avoid computing
                     86: atan2(0,0) must be indifferent to its value.
                     87: Programs that require it to be invalid are vulnerable
                     88: to diverse reactions to that invalidity on diverse computer systems. 
                     89: .IP (2) \w'\0\0\0\0'u
                     90: Atan2 is used mostly to convert from rectangular (x,y)
                     91: to polar
                     92: .if n\
                     93: (r,theta)
                     94: .if t\
                     95: (r,\(*h)
                     96: coordinates that must satisfy x =
                     97: .if n\
                     98: r\(**cos theta
                     99: .if t\
                    100: r\(**cos\(*h
                    101: and y =
                    102: .if n\
                    103: r\(**sin theta.
                    104: .if t\
                    105: r\(**sin\(*h.
                    106: These equations are satisfied when (x=0,y=0)
                    107: is mapped to 
                    108: .if n \
                    109: (r=0,theta=0)
                    110: .if t \
                    111: (r=0,\(*h=0)
                    112: on a VAX.  In general, conversions to polar coordinates
                    113: should be computed thus:
                    114: .nf
                    115: .ta 1iR +1n +\w' := hypot(x,y);'u+0.5i
                    116: .if n \{\
                    117:        r       := hypot(x,y);  ... := sqrt(x\(**x+y\(**y)
                    118:        theta   := atan2(y,x).
                    119: .ta \}
                    120: .if t \{\
                    121:        r       := hypot(x,y);  ... := \(sr(x\u\s82\s10\d+y\u\s82\s10\d)
                    122:        \(*h    := atan2(y,x).
                    123: .ta \}
                    124: .fi
                    125: .IP (3) \w'\0\0\0\0'u
                    126: The foregoing formulas need not be altered to cope in a
                    127: reasonable way with signed zeros and infinities
                    128: on a machine that conforms to IEEE 754;
                    129: the versions of hypot and atan2 provided for
                    130: such a machine are designed to handle all cases.
                    131: That is why atan2(\(+-0,\-0) =
                    132: .Pi , \(+-
                    133: for instance.
                    134: In general the formulas above are equivalent to these:
                    135: .RS
                    136: .nf
                    137: .if n \
                    138: r := sqrt(x\(**x+y\(**y); if r = 0 then x := copysign(1,x);
                    139: .if t \
                    140: r := \(sr(x\(**x+y\(**y);\0\0if r = 0 then x := copysign(1,x);
                    141: .br
                    142: .if n \
                    143: .ta 1i
                    144: .if t \
                    145: .ta \w'if x > 0'u+2n +\w'then'u+2n
                    146: .if n \
                    147: if x > 0       then theta := 2\(**atan(y/(r+x))
                    148: .if t \
                    149: if x > 0       then    \(*h := 2\(**atan(y/(r+x))
                    150: .if n \
                    151:        else theta := 2\(**atan((r\-x)/y);
                    152: .if t \
                    153:        else    \(*h := 2\(**atan((r\-x)/y);
                    154: .fi
                    155: .RE
                    156: except if r is infinite then atan2 will yield an
                    157: appropriate multiple of
                    158: .Pi /4
                    159: that would otherwise have to be obtained by taking limits.
                    160: .SH ERROR (due to Roundoff etc.)
                    161: Let P stand for the number stored in the computer in place of
                    162: .Pi " = 3.14159 26535 89793 23846 26433 ... ."
                    163: Let "trig" stand for one of "sin", "cos" or "tan".  Then
                    164: the expression "trig(x)" in a program actually produces an
                    165: approximation to
                    166: .Pi /P), trig(x\(**
                    167: and "atrig(x)" approximates
                    168: .Pi )\(**atrig(x). (P/
                    169: The approximations are close,  within 0.9 \*(ups for sin,
                    170: cos and atan, within 2.2 \*(ups for tan, asin,
                    171: acos and atan2 on a VAX.  Moreover,
                    172: .Pi \& "P = "
                    173: in the codes that run on a VAX.
                    174: 
                    175: In the codes that run on other machines, P differs from
                    176: .Pi
                    177: by a fraction of an \*(up; the difference matters only if the argument
                    178: x is huge, and even then the difference is likely to be swamped by
                    179: the uncertainty in x.  Besides, every trigonometric identity that
                    180: does not involve
                    181: .Pi
                    182: explicitly is satisfied equally well regardless of whether
                    183: .Pi . "P = "
                    184: For instance,
                    185: .if n \
                    186: sin(x)**2+cos(x)**2\0=\01
                    187: .if t \
                    188: sin\u\s62\s10\d(x)+cos\u\s62\s10\d(x)\0=\01
                    189: and sin(2x)\0=\02\|sin(x)cos(x) to within a few \*(ups no matter how big
                    190: x may be.  Therefore the difference between P and
                    191: .Pi
                    192: is most unlikely to affect scientific and engineering computations.
                    193: .SH SEE ALSO
                    194: math(3M), hypot(3M), sqrt(3M), infnan(3M)
                    195: .SH AUTHOR
                    196: Robert P. Corbett, W. Kahan, Stuart\0I.\0McDonald, Peter\0Tang and,
                    197: for the codes for IEEE 754, Dr. Kwok\-Choi\0Ng.

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.