Move all files into ports/ subdirectory in preparation for merge with glibc
[glibc.git] / ports / sysdeps / m68k / m680x0 / fpu / e_atan2.c
blobb0742d3da695736419e8ddd42fcb314c50d272b5
1 /* Copyright (C) 1997, 1999, 2011 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 <http://www.gnu.org/licenses/>. */
18 #include <math.h>
19 #include <math_private.h>
20 #include "mathimpl.h"
22 #ifndef SUFF
23 #define SUFF
24 #endif
25 #ifndef float_type
26 #define float_type double
27 #endif
29 #define CONCATX(a,b) __CONCAT(a,b)
30 #define s(name) CONCATX(name,SUFF)
31 #define m81(func) __m81_u(s(func))
33 float_type
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)
45 z = x + y;
46 else if (y_cond & __M81_COND_ZERO)
48 if (x_cond & __M81_COND_NEG)
49 z = y_cond & __M81_COND_NEG ? -pi : pi;
50 else
51 z = y;
53 else if (x_cond & __M81_COND_INF)
55 if (y_cond & __M81_COND_INF)
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;
61 else
62 z = x_cond & __M81_COND_NEG ? pi : 0;
63 if (y_cond & __M81_COND_NEG)
64 z = -z;
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)
72 if (-x > -y)
73 z = -pi + m81(__atan) (y / x);
74 else
75 z = -pi_2 - m81(__atan) (x / y);
77 else
79 if (-x > y)
80 z = pi + m81(__atan) (y / x);
81 else
82 z = pi_2 - m81(__atan) (x / y);
85 else
87 if (y_cond & __M81_COND_NEG)
89 if (x > -y)
90 z = m81(__atan) (y / x);
91 else
92 z = -pi_2 - m81(__atan) (x / y);
94 else
96 if (x > y)
97 z = m81(__atan) (y / x);
98 else
99 z = pi_2 - m81(__atan) (x / y);
102 return z;
104 strong_alias (s(__ieee754_atan2), CONCATX (s (__atan2), _finite))