fail posix_spawn file_actions operations with negative fds
[musl.git] / src / complex / csinhf.c
blobeb1d98c524a7d3db59eb4fccbf06498bca279721
1 /* origin: FreeBSD /usr/src/lib/msun/src/s_csinhf.c */
2 /*-
3 * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
11 * disclaimer.
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.
31 #include "complex_impl.h"
33 static const float huge = 0x1p127;
35 float complex csinhf(float complex z)
37 float x, y, h;
38 int32_t hx, hy, ix, iy;
40 x = crealf(z);
41 y = cimagf(z);
43 GET_FLOAT_WORD(hx, x);
44 GET_FLOAT_WORD(hy, y);
46 ix = 0x7fffffff & hx;
47 iy = 0x7fffffff & hy;
49 if (ix < 0x7f800000 && iy < 0x7f800000) {
50 if (iy == 0)
51 return CMPLXF(sinhf(x), y);
52 if (ix < 0x41100000) /* small x: normal case */
53 return CMPLXF(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 CMPLXF(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(CMPLXF(fabsf(x), y), -1);
63 return CMPLXF(crealf(z) * copysignf(1, x), cimagf(z));
64 } else {
65 /* x >= 192.7: the result always overflows */
66 h = huge * x;
67 return CMPLXF(h * cosf(y), h * h * sinf(y));
71 if (ix == 0 && iy >= 0x7f800000)
72 return CMPLXF(copysignf(0, x * (y - y)), y - y);
74 if (iy == 0 && ix >= 0x7f800000) {
75 if ((hx & 0x7fffff) == 0)
76 return CMPLXF(x, y);
77 return CMPLXF(x, copysignf(0, y));
80 if (ix < 0x7f800000 && iy >= 0x7f800000)
81 return CMPLXF(y - y, x * (y - y));
83 if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) {
84 if (iy >= 0x7f800000)
85 return CMPLXF(x * x, x * (y - y));
86 return CMPLXF(x * cosf(y), INFINITY * sinf(y));
89 return CMPLXF((x * x) * (y - y), (x + x) * (y - y));