1 /* Return arc tangent of complex float type.
2 Copyright (C) 1997-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
21 #include <math_private.h>
22 #include <math-underflow.h>
26 M_DECL_FUNC (__catan
) (CFLOAT x
)
29 int rcls
= fpclassify (__real__ x
);
30 int icls
= fpclassify (__imag__ x
);
32 if (__glibc_unlikely (rcls
<= FP_INFINITE
|| icls
<= FP_INFINITE
))
34 if (rcls
== FP_INFINITE
)
36 __real__ res
= M_COPYSIGN (M_MLIT (M_PI_2
), __real__ x
);
37 __imag__ res
= M_COPYSIGN (0, __imag__ x
);
39 else if (icls
== FP_INFINITE
)
42 __real__ res
= M_COPYSIGN (M_MLIT (M_PI_2
), __real__ x
);
45 __imag__ res
= M_COPYSIGN (0, __imag__ x
);
47 else if (icls
== FP_ZERO
|| icls
== FP_INFINITE
)
50 __imag__ res
= M_COPYSIGN (0, __imag__ x
);
58 else if (__glibc_unlikely (rcls
== FP_ZERO
&& icls
== FP_ZERO
))
64 if (M_FABS (__real__ x
) >= 16 / M_EPSILON
65 || M_FABS (__imag__ x
) >= 16 / M_EPSILON
)
67 __real__ res
= M_COPYSIGN (M_MLIT (M_PI_2
), __real__ x
);
68 if (M_FABS (__real__ x
) <= 1)
69 __imag__ res
= 1 / __imag__ x
;
70 else if (M_FABS (__imag__ x
) <= 1)
71 __imag__ res
= __imag__ x
/ __real__ x
/ __real__ x
;
74 FLOAT h
= M_HYPOT (__real__ x
/ 2, __imag__ x
/ 2);
75 __imag__ res
= __imag__ x
/ h
/ h
/ 4;
80 FLOAT den
, absx
, absy
;
82 absx
= M_FABS (__real__ x
);
83 absy
= M_FABS (__imag__ x
);
91 if (absy
< M_EPSILON
/ 2)
93 den
= (1 - absx
) * (1 + absx
);
98 den
= (1 - absx
) * (1 + absx
) - absy
* absy
;
99 else if (absx
>= M_LIT (0.75) || absy
>= M_LIT (0.5))
100 den
= -M_SUF (__x2y2m1
) (absx
, absy
);
102 den
= (1 - absx
) * (1 + absx
) - absy
* absy
;
104 __real__ res
= M_LIT (0.5) * M_ATAN2 (2 * __real__ x
, den
);
106 if (M_FABS (__imag__ x
) == 1
107 && M_FABS (__real__ x
) < M_EPSILON
* M_EPSILON
)
108 __imag__ res
= (M_COPYSIGN (M_LIT (0.5), __imag__ x
)
110 - M_LOG (M_FABS (__real__ x
))));
113 FLOAT r2
= 0, num
, f
;
115 if (M_FABS (__real__ x
) >= M_EPSILON
* M_EPSILON
)
116 r2
= __real__ x
* __real__ x
;
118 num
= __imag__ x
+ 1;
119 num
= r2
+ num
* num
;
121 den
= __imag__ x
- 1;
122 den
= r2
+ den
* den
;
126 __imag__ res
= M_LIT (0.25) * M_LOG (f
);
129 num
= 4 * __imag__ x
;
130 __imag__ res
= M_LIT (0.25) * M_LOG1P (num
/ den
);
135 math_check_force_underflow_complex (res
);
141 declare_mgen_alias (__catan
, catan
)