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. 5 * 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. 15 * 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. 26 */ 27/* 28 * Hyperbolic sine of a complex argument z. See s_csinh.c for details. 29 */ 30 31#include "libm.h" 32 33static const float huge = 0x1p127; 34 35float complex csinhf(float complex z) 36{ 37 float x, y, h; 38 int32_t hx, hy, ix, iy; 39 40 x = crealf(z); 41 y = cimagf(z); 42 43 GET_FLOAT_WORD(hx, x); 44 GET_FLOAT_WORD(hy, y); 45 46 ix = 0x7fffffff & hx; 47 iy = 0x7fffffff & hy; 48 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)); 54 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)); 68 } 69 } 70 71 if (ix == 0 && iy >= 0x7f800000) 72 return CMPLXF(copysignf(0, x * (y - y)), y - y); 73 74 if (iy == 0 && ix >= 0x7f800000) { 75 if ((hx & 0x7fffff) == 0) 76 return CMPLXF(x, y); 77 return CMPLXF(x, copysignf(0, y)); 78 } 79 80 if (ix < 0x7f800000 && iy >= 0x7f800000) 81 return CMPLXF(y - y, x * (y - y)); 82 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)); 87 } 88 89 return CMPLXF((x * x) * (y - y), (x + x) * (y - y)); 90} 91