154359Sroberto/*	$NetBSD: n_atan.c,v 1.8 2024/06/09 13:35:38 riastradh Exp $	*/
254359Sroberto/*
354359Sroberto * Copyright (c) 1985, 1993
454359Sroberto *	The Regents of the University of California.  All rights reserved.
554359Sroberto *
654359Sroberto * Redistribution and use in source and binary forms, with or without
754359Sroberto * modification, are permitted provided that the following conditions
854359Sroberto * are met:
954359Sroberto * 1. Redistributions of source code must retain the above copyright
1054359Sroberto *    notice, this list of conditions and the following disclaimer.
1154359Sroberto * 2. Redistributions in binary form must reproduce the above copyright
1254359Sroberto *    notice, this list of conditions and the following disclaimer in the
1354359Sroberto *    documentation and/or other materials provided with the distribution.
1454359Sroberto * 3. Neither the name of the University nor the names of its contributors
1554359Sroberto *    may be used to endorse or promote products derived from this software
1654359Sroberto *    without specific prior written permission.
1754359Sroberto *
1854359Sroberto * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1954359Sroberto * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2054359Sroberto * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2154359Sroberto * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2254359Sroberto * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2354359Sroberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2454359Sroberto * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2554359Sroberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2654359Sroberto * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2754359Sroberto * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2854359Sroberto * SUCH DAMAGE.
2954359Sroberto */
3054359Sroberto
3154359Sroberto#include <sys/cdefs.h>
3254359Sroberto__RCSID("$NetBSD: n_atan.c,v 1.8 2024/06/09 13:35:38 riastradh Exp $");
3354359Sroberto
3454359Sroberto#ifndef lint
3554359Sroberto#if 0
3654359Srobertostatic char sccsid[] = "@(#)atan.c	8.1 (Berkeley) 6/4/93";
3754359Sroberto#endif
3854359Sroberto#endif /* not lint */
3954359Sroberto
4054359Sroberto/* ATAN(X)
4154359Sroberto * RETURNS ARC TANGENT OF X
4254359Sroberto * DOUBLE PRECISION (IEEE DOUBLE 53 bits, VAX D FORMAT 56 bits)
4354359Sroberto * CODED IN C BY K.C. NG, 4/16/85, REVISED ON 6/10/85.
4454359Sroberto *
4554359Sroberto * Required kernel function:
4654359Sroberto *	atan2(y,x)
4754359Sroberto *
4854359Sroberto * Method:
4954359Sroberto *	atan(x) = atan2(x,1.0).
5054359Sroberto *
5154359Sroberto * Special case:
5254359Sroberto *	if x is NaN, return x itself.
5354359Sroberto *
5454359Sroberto * Accuracy:
5554359Sroberto * 1)  If atan2() uses machine PI, then
5654359Sroberto *
5754359Sroberto *	atan(x) returns (PI/pi) * (the exact arc tangent of x) nearly rounded;
5854359Sroberto *	and PI is the exact pi rounded to machine precision (see atan2 for
5954359Sroberto *      details):
6054359Sroberto *
6154359Sroberto *	in decimal:
6254359Sroberto *		pi = 3.141592653589793 23846264338327 .....
6354359Sroberto *    53 bits   PI = 3.141592653589793 115997963 ..... ,
6454359Sroberto *    56 bits   PI = 3.141592653589793 227020265 ..... ,
6554359Sroberto *
6656746Sroberto *	in hexadecimal:
6754359Sroberto *		pi = 3.243F6A8885A308D313198A2E....
6854359Sroberto *    53 bits   PI = 3.243F6A8885A30  =  2 * 1.921FB54442D18	error=.276ulps
6954359Sroberto *    56 bits   PI = 3.243F6A8885A308 =  4 * .C90FDAA22168C2    error=.206ulps
7054359Sroberto *
7154359Sroberto *	In a test run with more than 200,000 random arguments on a VAX, the
7254359Sroberto *	maximum observed error in ulps (units in the last place) was
7354359Sroberto *	0.86 ulps.      (comparing against (PI/pi)*(exact atan(x))).
7456746Sroberto *
7556746Sroberto * 2)  If atan2() uses true pi, then
7654359Sroberto *
7756746Sroberto *	atan(x) returns the exact atan(x) with error below about 2 ulps.
7854359Sroberto *
7954359Sroberto *	In a test run with more than 1,024,000 random arguments on a VAX, the
8054359Sroberto *	maximum observed error in ulps (units in the last place) was
8154359Sroberto *	0.85 ulps.
8254359Sroberto */
8354359Sroberto
8454359Sroberto#include "namespace.h"
8554359Sroberto
8654359Sroberto#include "mathimpl.h"
8754359Sroberto
8854359Sroberto__weak_alias(atan, _atan)
8954359Sroberto__weak_alias(atanf, _atanf)
9054359Sroberto
9154359Srobertodouble
9254359Srobertoatan(double x)
9354359Sroberto{
9454359Sroberto	double one=1.0;
9554359Sroberto	return(atan2(x,one));
9654359Sroberto}
9754359Sroberto
9854359Srobertofloat
9956746Srobertoatanf(float x)
10054359Sroberto{
10154359Sroberto	float one=1.0;
10254359Sroberto	return (float)atan2(x,one);
10354359Sroberto}
10454359Sroberto
10554359Sroberto