11.8Sriastrad/* $NetBSD: n_atan.c,v 1.8 2024/06/09 13:35:38 riastradh 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.8Sriastrad#include <sys/cdefs.h> 321.8Sriastrad__RCSID("$NetBSD: n_atan.c,v 1.8 2024/06/09 13:35:38 riastradh Exp $"); 331.8Sriastrad 341.1Sragge#ifndef lint 351.2Sragge#if 0 361.1Sraggestatic char sccsid[] = "@(#)atan.c 8.1 (Berkeley) 6/4/93"; 371.2Sragge#endif 381.1Sragge#endif /* not lint */ 391.1Sragge 401.1Sragge/* ATAN(X) 411.1Sragge * RETURNS ARC TANGENT OF X 421.1Sragge * DOUBLE PRECISION (IEEE DOUBLE 53 bits, VAX D FORMAT 56 bits) 431.1Sragge * CODED IN C BY K.C. NG, 4/16/85, REVISED ON 6/10/85. 441.1Sragge * 451.1Sragge * Required kernel function: 461.3Ssimonb * atan2(y,x) 471.1Sragge * 481.3Ssimonb * Method: 491.3Ssimonb * atan(x) = atan2(x,1.0). 501.1Sragge * 511.1Sragge * Special case: 521.1Sragge * if x is NaN, return x itself. 531.1Sragge * 541.1Sragge * Accuracy: 551.1Sragge * 1) If atan2() uses machine PI, then 561.3Ssimonb * 571.1Sragge * atan(x) returns (PI/pi) * (the exact arc tangent of x) nearly rounded; 581.1Sragge * and PI is the exact pi rounded to machine precision (see atan2 for 591.1Sragge * details): 601.1Sragge * 611.1Sragge * in decimal: 621.3Ssimonb * pi = 3.141592653589793 23846264338327 ..... 631.1Sragge * 53 bits PI = 3.141592653589793 115997963 ..... , 641.3Ssimonb * 56 bits PI = 3.141592653589793 227020265 ..... , 651.1Sragge * 661.1Sragge * in hexadecimal: 671.1Sragge * pi = 3.243F6A8885A308D313198A2E.... 681.1Sragge * 53 bits PI = 3.243F6A8885A30 = 2 * 1.921FB54442D18 error=.276ulps 691.1Sragge * 56 bits PI = 3.243F6A8885A308 = 4 * .C90FDAA22168C2 error=.206ulps 701.3Ssimonb * 711.3Ssimonb * In a test run with more than 200,000 random arguments on a VAX, the 721.1Sragge * maximum observed error in ulps (units in the last place) was 731.1Sragge * 0.86 ulps. (comparing against (PI/pi)*(exact atan(x))). 741.1Sragge * 751.1Sragge * 2) If atan2() uses true pi, then 761.1Sragge * 771.1Sragge * atan(x) returns the exact atan(x) with error below about 2 ulps. 781.1Sragge * 791.3Ssimonb * In a test run with more than 1,024,000 random arguments on a VAX, the 801.1Sragge * maximum observed error in ulps (units in the last place) was 811.1Sragge * 0.85 ulps. 821.1Sragge */ 831.7Sriastrad 841.7Sriastrad#include "namespace.h" 851.7Sriastrad 861.2Sragge#include "mathimpl.h" 871.1Sragge 881.7Sriastrad__weak_alias(atan, _atan) 891.7Sriastrad__weak_alias(atanf, _atanf) 901.7Sriastrad 911.4Smattdouble 921.4Smattatan(double x) 931.1Sragge{ 941.2Sragge double one=1.0; 951.1Sragge return(atan2(x,one)); 961.1Sragge} 971.6Smartin 981.6Smartinfloat 991.6Smartinatanf(float x) 1001.6Smartin{ 1011.6Smartin float one=1.0; 1021.6Smartin return (float)atan2(x,one); 1031.6Smartin} 1041.6Smartin 105