1*24589Szliu /* 2*24589Szliu * Copyright (c) 1985 Regents of the University of California. 3*24589Szliu * 4*24589Szliu * Use and reproduction of this software are granted in accordance with 5*24589Szliu * the terms and conditions specified in the Berkeley Software License 6*24589Szliu * Agreement (in particular, this entails acknowledgement of the programs' 7*24589Szliu * source, and inclusion of this notice) with the additional understanding 8*24589Szliu * that all recipients should regard themselves as participants in an 9*24589Szliu * ongoing research project and hence should feel obligated to report 10*24589Szliu * their experiences (good or bad) with these elementary function codes, 11*24589Szliu * using "sendbug 4bsd-bugs@BERKELEY", to the authors. 12*24589Szliu */ 13*24589Szliu 14*24589Szliu #ifndef lint 15*24589Szliu static char sccsid[] = "@(#)atan.c 1.1 (ELEFUNT) 09/06/85"; 16*24589Szliu #endif not lint 17*24589Szliu 18*24589Szliu /* ATAN(X) 19*24589Szliu * RETURNS ARC TANGENT OF X 20*24589Szliu * DOUBLE PRECISION (IEEE DOUBLE 53 bits, VAX D FORMAT 56 bits) 21*24589Szliu * CODED IN C BY K.C. NG, 4/16/85, REVISED ON 6/10/85. 22*24589Szliu * 23*24589Szliu * Required kernel function: 24*24589Szliu * atan2(y,x) 25*24589Szliu * 26*24589Szliu * Method: 27*24589Szliu * atan(x) = atan2(x,1.0). 28*24589Szliu * 29*24589Szliu * Special case: 30*24589Szliu * if x is NaN, return x itself. 31*24589Szliu * 32*24589Szliu * Accuracy: 33*24589Szliu * 1) If atan2() uses machine PI, then 34*24589Szliu * 35*24589Szliu * atan(x) returns (PI/pi) * (the exact arc tangent of x) nearly rounded; 36*24589Szliu * and PI is the exact pi rounded to machine precision (see atan2 for 37*24589Szliu * details): 38*24589Szliu * 39*24589Szliu * in decimal: 40*24589Szliu * pi = 3.141592653589793 23846264338327 ..... 41*24589Szliu * 53 bits PI = 3.141592653589793 115997963 ..... , 42*24589Szliu * 56 bits PI = 3.141592653589793 227020265 ..... , 43*24589Szliu * 44*24589Szliu * in hexadecimal: 45*24589Szliu * pi = 3.243F6A8885A308D313198A2E.... 46*24589Szliu * 53 bits PI = 3.243F6A8885A30 = 2 * 1.921FB54442D18 error=.276ulps 47*24589Szliu * 56 bits PI = 3.243F6A8885A308 = 4 * .C90FDAA22168C2 error=.206ulps 48*24589Szliu * 49*24589Szliu * In a test run with more than 200,000 random arguments on a VAX, the 50*24589Szliu * maximum observed error in ulps (units in the last place) was 51*24589Szliu * 0.86 ulps. (comparing against (PI/pi)*(exact atan(x))). 52*24589Szliu * 53*24589Szliu * 2) If atan2() uses true pi, then 54*24589Szliu * 55*24589Szliu * atan(x) returns the exact atan(x) with error below about 2 ulps. 56*24589Szliu * 57*24589Szliu * In a test run with more than 1,024,000 random arguments on a VAX, the 58*24589Szliu * maximum observed error in ulps (units in the last place) was 59*24589Szliu * 0.85 ulps. 60*24589Szliu */ 61*24589Szliu 62*24589Szliu double atan(x) 63*24589Szliu double x; 64*24589Szliu { 65*24589Szliu double atan2(),one=1.0; 66*24589Szliu return(atan2(x,one)); 67*24589Szliu } 68