xref: /csrg-svn/lib/libm/common_source/atan.c (revision 61283)
134124Sbostic /*
2*61283Sbostic  * Copyright (c) 1985, 1993
3*61283Sbostic  *	The Regents of the University of California.  All rights reserved.
434124Sbostic  *
542655Sbostic  * %sccs.include.redist.c%
624589Szliu  */
724589Szliu 
824589Szliu #ifndef lint
9*61283Sbostic static char sccsid[] = "@(#)atan.c	8.1 (Berkeley) 06/04/93";
1034124Sbostic #endif /* not lint */
1124589Szliu 
1224589Szliu /* ATAN(X)
1324589Szliu  * RETURNS ARC TANGENT OF X
1424589Szliu  * DOUBLE PRECISION (IEEE DOUBLE 53 bits, VAX D FORMAT 56 bits)
1524589Szliu  * CODED IN C BY K.C. NG, 4/16/85, REVISED ON 6/10/85.
1624589Szliu  *
1724589Szliu  * Required kernel function:
1824589Szliu  *	atan2(y,x)
1924589Szliu  *
2024589Szliu  * Method:
2124589Szliu  *	atan(x) = atan2(x,1.0).
2224589Szliu  *
2324589Szliu  * Special case:
2424589Szliu  *	if x is NaN, return x itself.
2524589Szliu  *
2624589Szliu  * Accuracy:
2724589Szliu  * 1)  If atan2() uses machine PI, then
2824589Szliu  *
2924589Szliu  *	atan(x) returns (PI/pi) * (the exact arc tangent of x) nearly rounded;
3024589Szliu  *	and PI is the exact pi rounded to machine precision (see atan2 for
3124589Szliu  *      details):
3224589Szliu  *
3324589Szliu  *	in decimal:
3424589Szliu  *		pi = 3.141592653589793 23846264338327 .....
3524589Szliu  *    53 bits   PI = 3.141592653589793 115997963 ..... ,
3624589Szliu  *    56 bits   PI = 3.141592653589793 227020265 ..... ,
3724589Szliu  *
3824589Szliu  *	in hexadecimal:
3924589Szliu  *		pi = 3.243F6A8885A308D313198A2E....
4024589Szliu  *    53 bits   PI = 3.243F6A8885A30  =  2 * 1.921FB54442D18	error=.276ulps
4124589Szliu  *    56 bits   PI = 3.243F6A8885A308 =  4 * .C90FDAA22168C2    error=.206ulps
4224589Szliu  *
4324589Szliu  *	In a test run with more than 200,000 random arguments on a VAX, the
4424589Szliu  *	maximum observed error in ulps (units in the last place) was
4524589Szliu  *	0.86 ulps.      (comparing against (PI/pi)*(exact atan(x))).
4624589Szliu  *
4724589Szliu  * 2)  If atan2() uses true pi, then
4824589Szliu  *
4924589Szliu  *	atan(x) returns the exact atan(x) with error below about 2 ulps.
5024589Szliu  *
5124589Szliu  *	In a test run with more than 1,024,000 random arguments on a VAX, the
5224589Szliu  *	maximum observed error in ulps (units in the last place) was
5324589Szliu  *	0.85 ulps.
5424589Szliu  */
5524589Szliu 
atan(x)5624589Szliu double atan(x)
5724589Szliu double x;
5824589Szliu {
5924589Szliu 	double atan2(),one=1.0;
6024589Szliu 	return(atan2(x,one));
6124589Szliu }
62