Line | |
---|
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".
|
---|
4 | *
|
---|
5 | * Author: Ceriel J.H. Jacobs
|
---|
6 | */
|
---|
7 | /* $Header: /cvsup/minix/src/lib/math/atan2.c,v 1.1.1.1 2005/04/21 14:56:24 beng Exp $ */
|
---|
8 |
|
---|
9 | #include <math.h>
|
---|
10 | #include <errno.h>
|
---|
11 | #include "localmath.h"
|
---|
12 |
|
---|
13 | double
|
---|
14 | atan2(double y, double x)
|
---|
15 | {
|
---|
16 | double absx, absy, val;
|
---|
17 |
|
---|
18 | if (x == 0 && y == 0) {
|
---|
19 | errno = EDOM;
|
---|
20 | return 0;
|
---|
21 | }
|
---|
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;
|
---|
27 | }
|
---|
28 | if (absx - absy == absx) {
|
---|
29 | /* y negligible compared to x */
|
---|
30 | val = 0.0;
|
---|
31 | }
|
---|
32 | else val = atan(y/x);
|
---|
33 | if (x > 0) {
|
---|
34 | /* first or fourth quadrant; already correct */
|
---|
35 | return val;
|
---|
36 | }
|
---|
37 | if (y < 0) {
|
---|
38 | /* third quadrant */
|
---|
39 | return val - M_PI;
|
---|
40 | }
|
---|
41 | return val + M_PI;
|
---|
42 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.