n_atan.c revision 1.1
11.1Sragge/*	$NetBSD: n_atan.c,v 1.1 1995/10/10 23:36:36 ragge 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.1Sraggestatic char sccsid[] = "@(#)atan.c	8.1 (Berkeley) 6/4/93";
371.1Sragge#endif /* not lint */
381.1Sragge
391.1Sragge/* ATAN(X)
401.1Sragge * RETURNS ARC TANGENT OF X
411.1Sragge * DOUBLE PRECISION (IEEE DOUBLE 53 bits, VAX D FORMAT 56 bits)
421.1Sragge * CODED IN C BY K.C. NG, 4/16/85, REVISED ON 6/10/85.
431.1Sragge *
441.1Sragge * Required kernel function:
451.1Sragge *	atan2(y,x)
461.1Sragge *
471.1Sragge * Method:
481.1Sragge *	atan(x) = atan2(x,1.0).
491.1Sragge *
501.1Sragge * Special case:
511.1Sragge *	if x is NaN, return x itself.
521.1Sragge *
531.1Sragge * Accuracy:
541.1Sragge * 1)  If atan2() uses machine PI, then
551.1Sragge *
561.1Sragge *	atan(x) returns (PI/pi) * (the exact arc tangent of x) nearly rounded;
571.1Sragge *	and PI is the exact pi rounded to machine precision (see atan2 for
581.1Sragge *      details):
591.1Sragge *
601.1Sragge *	in decimal:
611.1Sragge *		pi = 3.141592653589793 23846264338327 .....
621.1Sragge *    53 bits   PI = 3.141592653589793 115997963 ..... ,
631.1Sragge *    56 bits   PI = 3.141592653589793 227020265 ..... ,
641.1Sragge *
651.1Sragge *	in hexadecimal:
661.1Sragge *		pi = 3.243F6A8885A308D313198A2E....
671.1Sragge *    53 bits   PI = 3.243F6A8885A30  =  2 * 1.921FB54442D18	error=.276ulps
681.1Sragge *    56 bits   PI = 3.243F6A8885A308 =  4 * .C90FDAA22168C2    error=.206ulps
691.1Sragge *
701.1Sragge *	In a test run with more than 200,000 random arguments on a VAX, the
711.1Sragge *	maximum observed error in ulps (units in the last place) was
721.1Sragge *	0.86 ulps.      (comparing against (PI/pi)*(exact atan(x))).
731.1Sragge *
741.1Sragge * 2)  If atan2() uses true pi, then
751.1Sragge *
761.1Sragge *	atan(x) returns the exact atan(x) with error below about 2 ulps.
771.1Sragge *
781.1Sragge *	In a test run with more than 1,024,000 random arguments on a VAX, the
791.1Sragge *	maximum observed error in ulps (units in the last place) was
801.1Sragge *	0.85 ulps.
811.1Sragge */
821.1Sragge
831.1Sraggedouble atan(x)
841.1Sraggedouble x;
851.1Sragge{
861.1Sragge	double atan2(),one=1.0;
871.1Sragge	return(atan2(x,one));
881.1Sragge}
89