xref: /csrg-svn/lib/libm/common_source/atan.c (revision 34124)
1*34124Sbostic /*
224589Szliu  * Copyright (c) 1985 Regents of the University of California.
3*34124Sbostic  * All rights reserved.
4*34124Sbostic  *
5*34124Sbostic  * Redistribution and use in source and binary forms are permitted
6*34124Sbostic  * provided that this notice is preserved and that due credit is given
7*34124Sbostic  * to the University of California at Berkeley. The name of the University
8*34124Sbostic  * may not be used to endorse or promote products derived from this
9*34124Sbostic  * software without specific prior written permission. This software
10*34124Sbostic  * is provided ``as is'' without express or implied warranty.
11*34124Sbostic  *
12*34124Sbostic  * All recipients should regard themselves as participants in an ongoing
13*34124Sbostic  * research project and hence should feel obligated to report their
14*34124Sbostic  * experiences (good or bad) with these elementary function codes, using
15*34124Sbostic  * the sendbug(8) program, to the authors.
1624589Szliu  */
1724589Szliu 
1824589Szliu #ifndef lint
19*34124Sbostic static char sccsid[] = "@(#)atan.c	5.2 (Berkeley) 04/29/88";
20*34124Sbostic #endif /* not lint */
2124589Szliu 
2224589Szliu /* ATAN(X)
2324589Szliu  * RETURNS ARC TANGENT OF X
2424589Szliu  * DOUBLE PRECISION (IEEE DOUBLE 53 bits, VAX D FORMAT 56 bits)
2524589Szliu  * CODED IN C BY K.C. NG, 4/16/85, REVISED ON 6/10/85.
2624589Szliu  *
2724589Szliu  * Required kernel function:
2824589Szliu  *	atan2(y,x)
2924589Szliu  *
3024589Szliu  * Method:
3124589Szliu  *	atan(x) = atan2(x,1.0).
3224589Szliu  *
3324589Szliu  * Special case:
3424589Szliu  *	if x is NaN, return x itself.
3524589Szliu  *
3624589Szliu  * Accuracy:
3724589Szliu  * 1)  If atan2() uses machine PI, then
3824589Szliu  *
3924589Szliu  *	atan(x) returns (PI/pi) * (the exact arc tangent of x) nearly rounded;
4024589Szliu  *	and PI is the exact pi rounded to machine precision (see atan2 for
4124589Szliu  *      details):
4224589Szliu  *
4324589Szliu  *	in decimal:
4424589Szliu  *		pi = 3.141592653589793 23846264338327 .....
4524589Szliu  *    53 bits   PI = 3.141592653589793 115997963 ..... ,
4624589Szliu  *    56 bits   PI = 3.141592653589793 227020265 ..... ,
4724589Szliu  *
4824589Szliu  *	in hexadecimal:
4924589Szliu  *		pi = 3.243F6A8885A308D313198A2E....
5024589Szliu  *    53 bits   PI = 3.243F6A8885A30  =  2 * 1.921FB54442D18	error=.276ulps
5124589Szliu  *    56 bits   PI = 3.243F6A8885A308 =  4 * .C90FDAA22168C2    error=.206ulps
5224589Szliu  *
5324589Szliu  *	In a test run with more than 200,000 random arguments on a VAX, the
5424589Szliu  *	maximum observed error in ulps (units in the last place) was
5524589Szliu  *	0.86 ulps.      (comparing against (PI/pi)*(exact atan(x))).
5624589Szliu  *
5724589Szliu  * 2)  If atan2() uses true pi, then
5824589Szliu  *
5924589Szliu  *	atan(x) returns the exact atan(x) with error below about 2 ulps.
6024589Szliu  *
6124589Szliu  *	In a test run with more than 1,024,000 random arguments on a VAX, the
6224589Szliu  *	maximum observed error in ulps (units in the last place) was
6324589Szliu  *	0.85 ulps.
6424589Szliu  */
6524589Szliu 
6624589Szliu double atan(x)
6724589Szliu double x;
6824589Szliu {
6924589Szliu 	double atan2(),one=1.0;
7024589Szliu 	return(atan2(x,one));
7124589Szliu }
72