n_atan.c revision 1.4
11.4Smatt/* $NetBSD: n_atan.c,v 1.4 2002/06/15 00:10:17 matt Exp $ */ 21.1Sragge/* 31.1Sragge * Copyright (c) 1985, 1993 41.1Sragge * The Regents of the University of California. All rights reserved. 51.1Sragge * 61.1Sragge * Redistribution and use in source and binary forms, with or without 71.1Sragge * modification, are permitted provided that the following conditions 81.1Sragge * are met: 91.1Sragge * 1. Redistributions of source code must retain the above copyright 101.1Sragge * notice, this list of conditions and the following disclaimer. 111.1Sragge * 2. Redistributions in binary form must reproduce the above copyright 121.1Sragge * notice, this list of conditions and the following disclaimer in the 131.1Sragge * documentation and/or other materials provided with the distribution. 141.1Sragge * 3. All advertising materials mentioning features or use of this software 151.1Sragge * must display the following acknowledgement: 161.1Sragge * This product includes software developed by the University of 171.1Sragge * California, Berkeley and its contributors. 181.1Sragge * 4. Neither the name of the University nor the names of its contributors 191.1Sragge * may be used to endorse or promote products derived from this software 201.1Sragge * without specific prior written permission. 211.1Sragge * 221.1Sragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231.1Sragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241.1Sragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251.1Sragge * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261.1Sragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271.1Sragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281.1Sragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291.1Sragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301.1Sragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311.1Sragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321.1Sragge * SUCH DAMAGE. 331.1Sragge */ 341.1Sragge 351.1Sragge#ifndef lint 361.2Sragge#if 0 371.1Sraggestatic char sccsid[] = "@(#)atan.c 8.1 (Berkeley) 6/4/93"; 381.2Sragge#endif 391.1Sragge#endif /* not lint */ 401.1Sragge 411.1Sragge/* ATAN(X) 421.1Sragge * RETURNS ARC TANGENT OF X 431.1Sragge * DOUBLE PRECISION (IEEE DOUBLE 53 bits, VAX D FORMAT 56 bits) 441.1Sragge * CODED IN C BY K.C. NG, 4/16/85, REVISED ON 6/10/85. 451.1Sragge * 461.1Sragge * Required kernel function: 471.3Ssimonb * atan2(y,x) 481.1Sragge * 491.3Ssimonb * Method: 501.3Ssimonb * atan(x) = atan2(x,1.0). 511.1Sragge * 521.1Sragge * Special case: 531.1Sragge * if x is NaN, return x itself. 541.1Sragge * 551.1Sragge * Accuracy: 561.1Sragge * 1) If atan2() uses machine PI, then 571.3Ssimonb * 581.1Sragge * atan(x) returns (PI/pi) * (the exact arc tangent of x) nearly rounded; 591.1Sragge * and PI is the exact pi rounded to machine precision (see atan2 for 601.1Sragge * details): 611.1Sragge * 621.1Sragge * in decimal: 631.3Ssimonb * pi = 3.141592653589793 23846264338327 ..... 641.1Sragge * 53 bits PI = 3.141592653589793 115997963 ..... , 651.3Ssimonb * 56 bits PI = 3.141592653589793 227020265 ..... , 661.1Sragge * 671.1Sragge * in hexadecimal: 681.1Sragge * pi = 3.243F6A8885A308D313198A2E.... 691.1Sragge * 53 bits PI = 3.243F6A8885A30 = 2 * 1.921FB54442D18 error=.276ulps 701.1Sragge * 56 bits PI = 3.243F6A8885A308 = 4 * .C90FDAA22168C2 error=.206ulps 711.3Ssimonb * 721.3Ssimonb * In a test run with more than 200,000 random arguments on a VAX, the 731.1Sragge * maximum observed error in ulps (units in the last place) was 741.1Sragge * 0.86 ulps. (comparing against (PI/pi)*(exact atan(x))). 751.1Sragge * 761.1Sragge * 2) If atan2() uses true pi, then 771.1Sragge * 781.1Sragge * atan(x) returns the exact atan(x) with error below about 2 ulps. 791.1Sragge * 801.3Ssimonb * In a test run with more than 1,024,000 random arguments on a VAX, the 811.1Sragge * maximum observed error in ulps (units in the last place) was 821.1Sragge * 0.85 ulps. 831.1Sragge */ 841.2Sragge#include "mathimpl.h" 851.1Sragge 861.4Smattdouble 871.4Smattatan(double x) 881.1Sragge{ 891.2Sragge double one=1.0; 901.1Sragge return(atan2(x,one)); 911.1Sragge} 92