1 /* origin: FreeBSD /usr/src/lib/msun/src/s_csinhf.c */
3 * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * 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.
33 static const float huge = 0x1p127;
35 float complex csinhf(float complex z)
38 int32_t hx, hy, ix, iy;
43 GET_FLOAT_WORD(hx, x);
44 GET_FLOAT_WORD(hy, y);
49 if (ix < 0x7f800000 && iy < 0x7f800000) {
51 return cpackf(sinhf(x), y);
52 if (ix < 0x41100000) /* small x: normal case */
53 return cpackf(sinhf(x) * cosf(y), coshf(x) * sinf(y));
55 /* |x| >= 9, so cosh(x) ~= exp(|x|) */
56 if (ix < 0x42b17218) {
57 /* x < 88.7: expf(|x|) won't overflow */
58 h = expf(fabsf(x)) * 0.5f;
59 return cpackf(copysignf(h, x) * cosf(y), h * sinf(y));
60 } else if (ix < 0x4340b1e7) {
61 /* x < 192.7: scale to avoid overflow */
62 z = __ldexp_cexpf(cpackf(fabsf(x), y), -1);
63 return cpackf(crealf(z) * copysignf(1, x), cimagf(z));
65 /* x >= 192.7: the result always overflows */
67 return cpackf(h * cosf(y), h * h * sinf(y));
71 if (ix == 0 && iy >= 0x7f800000)
72 return cpackf(copysignf(0, x * (y - y)), y - y);
74 if (iy == 0 && ix >= 0x7f800000) {
75 if ((hx & 0x7fffff) == 0)
77 return cpackf(x, copysignf(0, y));
80 if (ix < 0x7f800000 && iy >= 0x7f800000)
81 return cpackf(y - y, x * (y - y));
83 if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) {
85 return cpackf(x * x, x * (y - y));
86 return cpackf(x * cosf(y), INFINITY * sinf(y));
89 return cpackf((x * x) * (y - y), (x + x) * (y - y));