1 /* Return arc hyperbole sine for float value, with the imaginary part
2 of the result possibly adjusted for use in computing other
4 Copyright (C) 1997-2015 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
23 #include <math_private.h>
26 /* Return the complex inverse hyperbolic sine of finite nonzero Z,
27 with the imaginary part of the result subtracted from pi/2 if ADJ
31 __kernel_casinhf (__complex__
float x
, int adj
)
33 __complex__
float res
;
37 /* Avoid cancellation by reducing to the first quadrant. */
38 rx
= fabsf (__real__ x
);
39 ix
= fabsf (__imag__ x
);
41 if (rx
>= 1.0f
/ FLT_EPSILON
|| ix
>= 1.0f
/ FLT_EPSILON
)
43 /* For large x in the first quadrant, x + csqrt (1 + x * x)
44 is sufficiently close to 2 * x to make no significant
45 difference to the result; avoid possible overflow from
46 the squaring and addition. */
53 __real__ y
= __copysignf (__imag__ y
, __imag__ x
);
58 __real__ res
+= (float) M_LN2
;
60 else if (rx
>= 0.5f
&& ix
< FLT_EPSILON
/ 8.0f
)
62 float s
= __ieee754_hypotf (1.0f
, rx
);
64 __real__ res
= __ieee754_logf (rx
+ s
);
66 __imag__ res
= __ieee754_atan2f (s
, __imag__ x
);
68 __imag__ res
= __ieee754_atan2f (ix
, s
);
70 else if (rx
< FLT_EPSILON
/ 8.0f
&& ix
>= 1.5f
)
72 float s
= __ieee754_sqrtf ((ix
+ 1.0f
) * (ix
- 1.0f
));
74 __real__ res
= __ieee754_logf (ix
+ s
);
76 __imag__ res
= __ieee754_atan2f (rx
, __copysignf (s
, __imag__ x
));
78 __imag__ res
= __ieee754_atan2f (s
, rx
);
80 else if (ix
> 1.0f
&& ix
< 1.5f
&& rx
< 0.5f
)
82 if (rx
< FLT_EPSILON
* FLT_EPSILON
)
84 float ix2m1
= (ix
+ 1.0f
) * (ix
- 1.0f
);
85 float s
= __ieee754_sqrtf (ix2m1
);
87 __real__ res
= __log1pf (2.0f
* (ix2m1
+ ix
* s
)) / 2.0f
;
89 __imag__ res
= __ieee754_atan2f (rx
, __copysignf (s
, __imag__ x
));
91 __imag__ res
= __ieee754_atan2f (s
, rx
);
95 float ix2m1
= (ix
+ 1.0f
) * (ix
- 1.0f
);
97 float f
= rx2
* (2.0f
+ rx2
+ 2.0f
* ix
* ix
);
98 float d
= __ieee754_sqrtf (ix2m1
* ix2m1
+ f
);
101 float r1
= __ieee754_sqrtf ((dm
+ rx2
) / 2.0f
);
102 float r2
= rx
* ix
/ r1
;
105 = __log1pf (rx2
+ dp
+ 2.0f
* (rx
* r1
+ ix
* r2
)) / 2.0f
;
107 __imag__ res
= __ieee754_atan2f (rx
+ r1
, __copysignf (ix
+ r2
,
110 __imag__ res
= __ieee754_atan2f (ix
+ r2
, rx
+ r1
);
113 else if (ix
== 1.0f
&& rx
< 0.5f
)
115 if (rx
< FLT_EPSILON
/ 8.0f
)
117 __real__ res
= __log1pf (2.0f
* (rx
+ __ieee754_sqrtf (rx
))) / 2.0f
;
119 __imag__ res
= __ieee754_atan2f (__ieee754_sqrtf (rx
),
120 __copysignf (1.0f
, __imag__ x
));
122 __imag__ res
= __ieee754_atan2f (1.0f
, __ieee754_sqrtf (rx
));
126 float d
= rx
* __ieee754_sqrtf (4.0f
+ rx
* rx
);
127 float s1
= __ieee754_sqrtf ((d
+ rx
* rx
) / 2.0f
);
128 float s2
= __ieee754_sqrtf ((d
- rx
* rx
) / 2.0f
);
130 __real__ res
= __log1pf (rx
* rx
+ d
+ 2.0f
* (rx
* s1
+ s2
)) / 2.0f
;
132 __imag__ res
= __ieee754_atan2f (rx
+ s1
,
133 __copysignf (1.0f
+ s2
,
136 __imag__ res
= __ieee754_atan2f (1.0f
+ s2
, rx
+ s1
);
139 else if (ix
< 1.0f
&& rx
< 0.5f
)
141 if (ix
>= FLT_EPSILON
)
143 if (rx
< FLT_EPSILON
* FLT_EPSILON
)
145 float onemix2
= (1.0f
+ ix
) * (1.0f
- ix
);
146 float s
= __ieee754_sqrtf (onemix2
);
148 __real__ res
= __log1pf (2.0f
* rx
/ s
) / 2.0f
;
150 __imag__ res
= __ieee754_atan2f (s
, __imag__ x
);
152 __imag__ res
= __ieee754_atan2f (ix
, s
);
156 float onemix2
= (1.0f
+ ix
) * (1.0f
- ix
);
158 float f
= rx2
* (2.0f
+ rx2
+ 2.0f
* ix
* ix
);
159 float d
= __ieee754_sqrtf (onemix2
* onemix2
+ f
);
160 float dp
= d
+ onemix2
;
162 float r1
= __ieee754_sqrtf ((dp
+ rx2
) / 2.0f
);
163 float r2
= rx
* ix
/ r1
;
166 = __log1pf (rx2
+ dm
+ 2.0f
* (rx
* r1
+ ix
* r2
)) / 2.0f
;
168 __imag__ res
= __ieee754_atan2f (rx
+ r1
,
169 __copysignf (ix
+ r2
,
172 __imag__ res
= __ieee754_atan2f (ix
+ r2
, rx
+ r1
);
177 float s
= __ieee754_hypotf (1.0f
, rx
);
179 __real__ res
= __log1pf (2.0f
* rx
* (rx
+ s
)) / 2.0f
;
181 __imag__ res
= __ieee754_atan2f (s
, __imag__ x
);
183 __imag__ res
= __ieee754_atan2f (ix
, s
);
185 if (__real__ res
< FLT_MIN
)
187 volatile float force_underflow
= __real__ res
* __real__ res
;
188 (void) force_underflow
;
193 __real__ y
= (rx
- ix
) * (rx
+ ix
) + 1.0f
;
194 __imag__ y
= 2.0f
* rx
* ix
;
203 float t
= __real__ y
;
204 __real__ y
= __copysignf (__imag__ y
, __imag__ x
);
211 /* Give results the correct sign for the original argument. */
212 __real__ res
= __copysignf (__real__ res
, __real__ x
);
213 __imag__ res
= __copysignf (__imag__ res
, (adj
? 1.0f
: __imag__ x
));