1989-05-10 16:08:14 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*
|
|
|
|
* Author: Ceriel J.H. Jacobs
|
|
|
|
*/
|
1994-06-24 14:02:31 +00:00
|
|
|
/* $Id$ */
|
1989-05-10 16:08:14 +00:00
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <errno.h>
|
2018-06-22 22:04:14 +00:00
|
|
|
#include <ack/config.h>
|
2018-06-21 20:33:47 +00:00
|
|
|
#include "localmath.h"
|
1989-05-10 16:08:14 +00:00
|
|
|
|
2018-06-22 22:04:14 +00:00
|
|
|
#if ACKCONF_WANT_FLOAT
|
|
|
|
|
1989-05-10 16:08:14 +00:00
|
|
|
double
|
|
|
|
atan2(double y, double x)
|
|
|
|
{
|
|
|
|
double absx, absy, val;
|
|
|
|
|
2018-06-21 20:33:47 +00:00
|
|
|
if (x == 0 && y == 0)
|
|
|
|
{
|
1989-05-10 16:08:14 +00:00
|
|
|
errno = EDOM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
absy = y < 0 ? -y : y;
|
|
|
|
absx = x < 0 ? -x : x;
|
2018-06-21 20:33:47 +00:00
|
|
|
if (absy - absx == absy)
|
|
|
|
{
|
1989-05-10 16:08:14 +00:00
|
|
|
/* x negligible compared to y */
|
|
|
|
return y < 0 ? -M_PI_2 : M_PI_2;
|
|
|
|
}
|
2018-06-21 20:33:47 +00:00
|
|
|
if (absx - absy == absx)
|
|
|
|
{
|
1989-05-10 16:08:14 +00:00
|
|
|
/* y negligible compared to x */
|
|
|
|
val = 0.0;
|
|
|
|
}
|
2018-06-21 20:33:47 +00:00
|
|
|
else
|
|
|
|
val = atan(y / x);
|
|
|
|
if (x > 0)
|
|
|
|
{
|
1989-05-10 16:08:14 +00:00
|
|
|
/* first or fourth quadrant; already correct */
|
|
|
|
return val;
|
|
|
|
}
|
2018-06-21 20:33:47 +00:00
|
|
|
if (y < 0)
|
|
|
|
{
|
1989-05-10 16:08:14 +00:00
|
|
|
/* third quadrant */
|
|
|
|
return val - M_PI;
|
|
|
|
}
|
|
|
|
return val + M_PI;
|
|
|
|
}
|
2018-06-22 22:04:14 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|