Remove mips dependency on alpha.
[jlayton/glibc.git] / ports / sysdeps / m68k / m680x0 / fpu / e_atan2.c
1 /* Copyright (C) 1997-2014 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3
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.
8
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.
13
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    <http://www.gnu.org/licenses/>.  */
17
18 #include <math.h>
19 #include <math_private.h>
20 #include "mathimpl.h"
21
22 #ifndef SUFF
23 #define SUFF
24 #endif
25 #ifndef float_type
26 #define float_type double
27 #endif
28
29 #define CONCATX(a,b) __CONCAT(a,b)
30 #define s(name) CONCATX(name,SUFF)
31 #define m81(func) __m81_u(s(func))
32
33 float_type
34 s(__ieee754_atan2) (float_type y, float_type x)
35 {
36   float_type pi, pi_2, z;
37   unsigned long y_cond, x_cond;
38
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);
43
44   if ((x_cond | y_cond) & __M81_COND_NAN)
45     z = x + y;
46   else if (y_cond & __M81_COND_ZERO)
47     {
48       if (x_cond & __M81_COND_NEG)
49         z = y_cond & __M81_COND_NEG ? -pi : pi;
50       else
51         z = y;
52     }
53   else if (x_cond & __M81_COND_INF)
54     {
55       if (y_cond & __M81_COND_INF)
56         {
57           float_type pi_4;
58           __asm ("fscale%.w %#-2, %0" : "=f" (pi_4) : "0" (pi));
59           z = x_cond & __M81_COND_NEG ? 3 * pi_4 : pi_4;
60         }
61       else
62         z = x_cond & __M81_COND_NEG ? pi : 0;
63       if (y_cond & __M81_COND_NEG)
64         z = -z;
65     }
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)
69     {
70       if (y_cond & __M81_COND_NEG)
71         {
72           if (-x > -y)
73             z = -pi + m81(__atan) (y / x);
74           else
75             z = -pi_2 - m81(__atan) (x / y);
76         }
77       else
78         {
79           if (-x > y)
80             z = pi + m81(__atan) (y / x);
81           else
82             z = pi_2 - m81(__atan) (x / y);
83         }
84     }
85   else
86     {
87       if (y_cond & __M81_COND_NEG)
88         {
89           if (x > -y)
90             z = m81(__atan) (y / x);
91           else
92             z = -pi_2 - m81(__atan) (x / y);
93         }
94       else
95         {
96           if (x > y)
97             z = m81(__atan) (y / x);
98           else
99             z = pi_2 - m81(__atan) (x / y);
100         }
101     }
102   return z;
103 }
104 strong_alias (s(__ieee754_atan2), CONCATX (s (__atan2), _finite))