n_atan.c revision 1.6
11.6Smartin/* $NetBSD: n_atan.c,v 1.6 2013/11/24 14:41:53 martin 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.5Sagc * 3. Neither the name of the University nor the names of its contributors 151.1Sragge * may be used to endorse or promote products derived from this software 161.1Sragge * without specific prior written permission. 171.1Sragge * 181.1Sragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 191.1Sragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 201.1Sragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 211.1Sragge * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 221.1Sragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 231.1Sragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 241.1Sragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 251.1Sragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 261.1Sragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 271.1Sragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 281.1Sragge * SUCH DAMAGE. 291.1Sragge */ 301.1Sragge 311.1Sragge#ifndef lint 321.2Sragge#if 0 331.1Sraggestatic char sccsid[] = "@(#)atan.c 8.1 (Berkeley) 6/4/93"; 341.2Sragge#endif 351.1Sragge#endif /* not lint */ 361.1Sragge 371.1Sragge/* ATAN(X) 381.1Sragge * RETURNS ARC TANGENT OF X 391.1Sragge * DOUBLE PRECISION (IEEE DOUBLE 53 bits, VAX D FORMAT 56 bits) 401.1Sragge * CODED IN C BY K.C. NG, 4/16/85, REVISED ON 6/10/85. 411.1Sragge * 421.1Sragge * Required kernel function: 431.3Ssimonb * atan2(y,x) 441.1Sragge * 451.3Ssimonb * Method: 461.3Ssimonb * atan(x) = atan2(x,1.0). 471.1Sragge * 481.1Sragge * Special case: 491.1Sragge * if x is NaN, return x itself. 501.1Sragge * 511.1Sragge * Accuracy: 521.1Sragge * 1) If atan2() uses machine PI, then 531.3Ssimonb * 541.1Sragge * atan(x) returns (PI/pi) * (the exact arc tangent of x) nearly rounded; 551.1Sragge * and PI is the exact pi rounded to machine precision (see atan2 for 561.1Sragge * details): 571.1Sragge * 581.1Sragge * in decimal: 591.3Ssimonb * pi = 3.141592653589793 23846264338327 ..... 601.1Sragge * 53 bits PI = 3.141592653589793 115997963 ..... , 611.3Ssimonb * 56 bits PI = 3.141592653589793 227020265 ..... , 621.1Sragge * 631.1Sragge * in hexadecimal: 641.1Sragge * pi = 3.243F6A8885A308D313198A2E.... 651.1Sragge * 53 bits PI = 3.243F6A8885A30 = 2 * 1.921FB54442D18 error=.276ulps 661.1Sragge * 56 bits PI = 3.243F6A8885A308 = 4 * .C90FDAA22168C2 error=.206ulps 671.3Ssimonb * 681.3Ssimonb * In a test run with more than 200,000 random arguments on a VAX, the 691.1Sragge * maximum observed error in ulps (units in the last place) was 701.1Sragge * 0.86 ulps. (comparing against (PI/pi)*(exact atan(x))). 711.1Sragge * 721.1Sragge * 2) If atan2() uses true pi, then 731.1Sragge * 741.1Sragge * atan(x) returns the exact atan(x) with error below about 2 ulps. 751.1Sragge * 761.3Ssimonb * In a test run with more than 1,024,000 random arguments on a VAX, the 771.1Sragge * maximum observed error in ulps (units in the last place) was 781.1Sragge * 0.85 ulps. 791.1Sragge */ 801.2Sragge#include "mathimpl.h" 811.1Sragge 821.4Smattdouble 831.4Smattatan(double x) 841.1Sragge{ 851.2Sragge double one=1.0; 861.1Sragge return(atan2(x,one)); 871.1Sragge} 881.6Smartin 891.6Smartinfloat 901.6Smartinatanf(float x) 911.6Smartin{ 921.6Smartin float one=1.0; 931.6Smartin return (float)atan2(x,one); 941.6Smartin} 951.6Smartin 96