2 * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Hyperbolic sine of a complex argument z. See s_csinh.c for details.
31 //__FBSDID("$FreeBSD: src/lib/msun/src/s_csinhf.c,v 1.2 2011/10/21 06:29:32 das Exp $");
36 #include "math_private.h"
38 static const float huge
= 0x1p
127;
41 csinhf(float complex z
)
44 int32_t hx
, hy
, ix
, iy
;
49 GET_FLOAT_WORD(hx
, x
);
50 GET_FLOAT_WORD(hy
, y
);
55 if (ix
< 0x7f800000 && iy
< 0x7f800000) {
57 return (CMPLXF(sinhf(x
), y
));
58 if (ix
< 0x41100000) /* |x| < 9: normal case */
59 return (CMPLXF(sinhf(x
) * cosf(y
), coshf(x
) * sinf(y
)));
61 /* |x| >= 9, so cosh(x) ~= exp(|x|) */
62 if (ix
< 0x42b17218) {
63 /* x < 88.7: expf(|x|) won't overflow */
64 h
= expf(fabsf(x
)) * 0.5F
;
65 return (CMPLXF(copysignf(h
, x
) * cosf(y
), h
* sinf(y
)));
66 } else if (ix
< 0x4340b1e7) {
67 /* x < 192.7: scale to avoid overflow */
68 z
= __ldexp_cexpf(CMPLXF(fabsf(x
), y
), -1);
69 return (CMPLXF(crealf(z
) * copysignf(1, x
), cimagf(z
)));
71 /* x >= 192.7: the result always overflows */
73 return (CMPLXF(h
* cosf(y
), h
* h
* sinf(y
)));
77 if (ix
== 0) /* && iy >= 0x7f800000 */
78 return (CMPLXF(x
, y
- y
));
80 if (iy
== 0) /* && ix >= 0x7f800000 */
81 return (CMPLXF(x
+ x
, y
));
83 if (ix
< 0x7f800000) /* && iy >= 0x7f800000 */
84 return (CMPLXF(y
- y
, y
- y
));
86 if (ix
== 0x7f800000) {
88 return (CMPLXF(x
, y
- y
));
89 return (CMPLXF(x
* cosf(y
), INFINITY
* sinf(y
)));
92 return (CMPLXF((x
+ x
) * (y
- y
), (x
* x
) * (y
- y
)));
96 csinf(float complex z
)
99 z
= csinhf(CMPLXF(-cimagf(z
), crealf(z
)));
100 return (CMPLXF(cimagf(z
), -crealf(z
)));