xref: /csrg-svn/lib/libm/common_source/atan.c (revision 42655)
134124Sbostic /*
224589Szliu  * Copyright (c) 1985 Regents of the University of California.
334124Sbostic  * All rights reserved.
434124Sbostic  *
5*42655Sbostic  * %sccs.include.redist.c%
634124Sbostic  *
734124Sbostic  * All recipients should regard themselves as participants in an ongoing
834124Sbostic  * research project and hence should feel obligated to report their
934124Sbostic  * experiences (good or bad) with these elementary function codes, using
1034124Sbostic  * the sendbug(8) program, to the authors.
1124589Szliu  */
1224589Szliu 
1324589Szliu #ifndef lint
14*42655Sbostic static char sccsid[] = "@(#)atan.c	5.4 (Berkeley) 06/01/90";
1534124Sbostic #endif /* not lint */
1624589Szliu 
1724589Szliu /* ATAN(X)
1824589Szliu  * RETURNS ARC TANGENT OF X
1924589Szliu  * DOUBLE PRECISION (IEEE DOUBLE 53 bits, VAX D FORMAT 56 bits)
2024589Szliu  * CODED IN C BY K.C. NG, 4/16/85, REVISED ON 6/10/85.
2124589Szliu  *
2224589Szliu  * Required kernel function:
2324589Szliu  *	atan2(y,x)
2424589Szliu  *
2524589Szliu  * Method:
2624589Szliu  *	atan(x) = atan2(x,1.0).
2724589Szliu  *
2824589Szliu  * Special case:
2924589Szliu  *	if x is NaN, return x itself.
3024589Szliu  *
3124589Szliu  * Accuracy:
3224589Szliu  * 1)  If atan2() uses machine PI, then
3324589Szliu  *
3424589Szliu  *	atan(x) returns (PI/pi) * (the exact arc tangent of x) nearly rounded;
3524589Szliu  *	and PI is the exact pi rounded to machine precision (see atan2 for
3624589Szliu  *      details):
3724589Szliu  *
3824589Szliu  *	in decimal:
3924589Szliu  *		pi = 3.141592653589793 23846264338327 .....
4024589Szliu  *    53 bits   PI = 3.141592653589793 115997963 ..... ,
4124589Szliu  *    56 bits   PI = 3.141592653589793 227020265 ..... ,
4224589Szliu  *
4324589Szliu  *	in hexadecimal:
4424589Szliu  *		pi = 3.243F6A8885A308D313198A2E....
4524589Szliu  *    53 bits   PI = 3.243F6A8885A30  =  2 * 1.921FB54442D18	error=.276ulps
4624589Szliu  *    56 bits   PI = 3.243F6A8885A308 =  4 * .C90FDAA22168C2    error=.206ulps
4724589Szliu  *
4824589Szliu  *	In a test run with more than 200,000 random arguments on a VAX, the
4924589Szliu  *	maximum observed error in ulps (units in the last place) was
5024589Szliu  *	0.86 ulps.      (comparing against (PI/pi)*(exact atan(x))).
5124589Szliu  *
5224589Szliu  * 2)  If atan2() uses true pi, then
5324589Szliu  *
5424589Szliu  *	atan(x) returns the exact atan(x) with error below about 2 ulps.
5524589Szliu  *
5624589Szliu  *	In a test run with more than 1,024,000 random arguments on a VAX, the
5724589Szliu  *	maximum observed error in ulps (units in the last place) was
5824589Szliu  *	0.85 ulps.
5924589Szliu  */
6024589Szliu 
6124589Szliu double atan(x)
6224589Szliu double x;
6324589Szliu {
6424589Szliu 	double atan2(),one=1.0;
6524589Szliu 	return(atan2(x,one));
6624589Szliu }
67