]>
git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/m68k/m680x0/fpu/e_atan2.c
1 /* Copyright (C) 1997-2020 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library. If not, see
16 <https://www.gnu.org/licenses/>. */
19 #include <math_private.h>
26 #define float_type double
29 #define CONCATX(a,b) __CONCAT(a,b)
30 #define s(name) CONCATX(name,SUFF)
31 #define m81(func) __m81_u(s(func))
34 s(__ieee754_atan2
) (float_type y
, float_type x
)
36 float_type pi
, pi_2
, z
;
37 unsigned long y_cond
, x_cond
;
39 __asm ("fmovecr%.x %#0, %0" : "=f" (pi
));
40 __asm ("fscale%.w %#-1, %0" : "=f" (pi_2
) : "0" (pi
));
41 y_cond
= __m81_test (y
);
42 x_cond
= __m81_test (x
);
44 if ((x_cond
| y_cond
) & __M81_COND_NAN
)
46 else if (y_cond
& __M81_COND_ZERO
)
48 if (x_cond
& __M81_COND_NEG
)
49 z
= y_cond
& __M81_COND_NEG
? -pi
: pi
;
53 else if (x_cond
& __M81_COND_INF
)
55 if (y_cond
& __M81_COND_INF
)
58 __asm ("fscale%.w %#-2, %0" : "=f" (pi_4
) : "0" (pi
));
59 z
= x_cond
& __M81_COND_NEG
? 3 * pi_4
: pi_4
;
62 z
= x_cond
& __M81_COND_NEG
? pi
: 0;
63 if (y_cond
& __M81_COND_NEG
)
66 else if (y_cond
& __M81_COND_INF
)
67 z
= y_cond
& __M81_COND_NEG
? -pi_2
: pi_2
;
68 else if (x_cond
& __M81_COND_NEG
)
70 if (y_cond
& __M81_COND_NEG
)
73 z
= -pi
+ m81(__atan
) (y
/ x
);
75 z
= -pi_2
- m81(__atan
) (x
/ y
);
80 z
= pi
+ m81(__atan
) (y
/ x
);
82 z
= pi_2
- m81(__atan
) (x
/ y
);
87 if (y_cond
& __M81_COND_NEG
)
90 z
= m81(__atan
) (y
/ x
);
92 z
= -pi_2
- m81(__atan
) (x
/ y
);
97 z
= m81(__atan
) (y
/ x
);
99 z
= pi_2
- m81(__atan
) (x
/ y
);
104 strong_alias (s(__ieee754_atan2
), CONCATX (s (__atan2
), _finite
))