blob: be5b9dd63f6928b88964bb14442473cf98294386 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# define TGSOURCE "atan2.c"
#include <math.h>
#include "nonstd/tgmath.h"
#include "errno.h"
#include "nonstd/assert.h"
/** arc tangent **/
TYPE TGFN(atan2)(TYPE y, TYPE x)
{
ASSERT_NONZERO(x);
if (y == 0 && x == 0) {
errno = EDOM; /* ARGUMENT(y) and ARGUMENT(x) are both LITERAL(0)) */
return TGHUGE;
}
if (0) {
errno = ERANGE; /* The result cannot be represented */
/* RETURN_FAILURE(CONSTANT(HUGE_VAL), A range error occurred); */
return TGHUGE;
}
TYPE ret = TGFN(tan)(y / x);
/* FIXME: quadrant */
/* RETURN_SUCCESS(a value in range `[-PI(), +PI()]'); */
return ret;
}
/***
functions compute the principal value of the arc tangent of
ARGUMENT(y)/ARGUMENT(x), using the signs of both to place the return value in
the correct quadrant.
***/
/*
IMPLEMENTATION(The value returned on a domain error, CONSTANT(HUGE_VAL))
LINK(m)
*/
/*
STDC(1)
*/
|