at_wini also needs a pci_reserve() for the pci compatability device, if
[minix3.git] / lib / math / atan2.c
blob0e253c746210cb26796f793eafb250d129ce8ae2
1 /*
2 * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 * Author: Ceriel J.H. Jacobs
6 */
7 /* $Header$ */
9 #include <math.h>
10 #include <errno.h>
11 #include "localmath.h"
13 double
14 atan2(double y, double x)
16 double absx, absy, val;
18 if (x == 0 && y == 0) {
19 errno = EDOM;
20 return 0;
22 absy = y < 0 ? -y : y;
23 absx = x < 0 ? -x : x;
24 if (absy - absx == absy) {
25 /* x negligible compared to y */
26 return y < 0 ? -M_PI_2 : M_PI_2;
28 if (absx - absy == absx) {
29 /* y negligible compared to x */
30 val = 0.0;
32 else val = atan(y/x);
33 if (x > 0) {
34 /* first or fourth quadrant; already correct */
35 return val;
37 if (y < 0) {
38 /* third quadrant */
39 return val - M_PI;
41 return val + M_PI;