1226458Sdas/*- 2226458Sdas * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl 3226458Sdas * All rights reserved. 4226458Sdas * 5226458Sdas * Redistribution and use in source and binary forms, with or without 6226458Sdas * modification, are permitted provided that the following conditions 7226458Sdas * are met: 8226458Sdas * 1. Redistributions of source code must retain the above copyright 9226458Sdas * notice unmodified, this list of conditions, and the following 10226458Sdas * disclaimer. 11226458Sdas * 2. Redistributions in binary form must reproduce the above copyright 12226458Sdas * notice, this list of conditions and the following disclaimer in the 13226458Sdas * documentation and/or other materials provided with the distribution. 14226458Sdas * 15226458Sdas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16226458Sdas * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17226458Sdas * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18226458Sdas * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19226458Sdas * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20226458Sdas * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21226458Sdas * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22226458Sdas * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23226458Sdas * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24226458Sdas * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25226458Sdas */ 26226458Sdas 27226458Sdas/* 28284810Stijl * Float version of csinh(). See s_csinh.c for details. 29226458Sdas */ 30226458Sdas 31226458Sdas#include <sys/cdefs.h> 32226458Sdas__FBSDID("$FreeBSD: releng/10.3/lib/msun/src/s_csinhf.c 284810 2015-06-25 13:01:10Z tijl $"); 33226458Sdas 34226458Sdas#include <complex.h> 35226458Sdas#include <math.h> 36226458Sdas 37226458Sdas#include "math_private.h" 38226458Sdas 39226599Sdasstatic const float huge = 0x1p127; 40226599Sdas 41226458Sdasfloat complex 42226458Sdascsinhf(float complex z) 43226458Sdas{ 44226599Sdas float x, y, h; 45226458Sdas int32_t hx, hy, ix, iy; 46226458Sdas 47226458Sdas x = crealf(z); 48226458Sdas y = cimagf(z); 49226458Sdas 50226458Sdas GET_FLOAT_WORD(hx, x); 51226458Sdas GET_FLOAT_WORD(hy, y); 52226458Sdas 53226458Sdas ix = 0x7fffffff & hx; 54226458Sdas iy = 0x7fffffff & hy; 55226458Sdas 56226458Sdas if (ix < 0x7f800000 && iy < 0x7f800000) { 57226458Sdas if (iy == 0) 58284810Stijl return (CMPLXF(sinhf(x), y)); 59284810Stijl if (ix < 0x41100000) /* |x| < 9: normal case */ 60284810Stijl return (CMPLXF(sinhf(x) * cosf(y), coshf(x) * sinf(y))); 61226599Sdas 62226599Sdas /* |x| >= 9, so cosh(x) ~= exp(|x|) */ 63226599Sdas if (ix < 0x42b17218) { 64226599Sdas /* x < 88.7: expf(|x|) won't overflow */ 65284810Stijl h = expf(fabsf(x)) * 0.5F; 66284810Stijl return (CMPLXF(copysignf(h, x) * cosf(y), h * sinf(y))); 67226599Sdas } else if (ix < 0x4340b1e7) { 68226599Sdas /* x < 192.7: scale to avoid overflow */ 69284810Stijl z = __ldexp_cexpf(CMPLXF(fabsf(x), y), -1); 70284810Stijl return (CMPLXF(crealf(z) * copysignf(1, x), cimagf(z))); 71226599Sdas } else { 72226599Sdas /* x >= 192.7: the result always overflows */ 73226599Sdas h = huge * x; 74284810Stijl return (CMPLXF(h * cosf(y), h * h * sinf(y))); 75226599Sdas } 76226458Sdas } 77226458Sdas 78284810Stijl if (ix == 0) /* && iy >= 0x7f800000 */ 79284810Stijl return (CMPLXF(x, y - y)); 80226458Sdas 81284810Stijl if (iy == 0) /* && ix >= 0x7f800000 */ 82284810Stijl return (CMPLXF(x + x, y)); 83226458Sdas 84284810Stijl if (ix < 0x7f800000) /* && iy >= 0x7f800000 */ 85284810Stijl return (CMPLXF(y - y, y - y)); 86226458Sdas 87284810Stijl if (ix == 0x7f800000) { 88226458Sdas if (iy >= 0x7f800000) 89284810Stijl return (CMPLXF(x, y - y)); 90284810Stijl return (CMPLXF(x * cosf(y), INFINITY * sinf(y))); 91226458Sdas } 92226458Sdas 93284810Stijl return (CMPLXF((x + x) * (y - y), (x * x) * (y - y))); 94226458Sdas} 95226458Sdas 96226458Sdasfloat complex 97226458Sdascsinf(float complex z) 98226458Sdas{ 99226458Sdas 100284810Stijl z = csinhf(CMPLXF(cimagf(z), crealf(z))); 101284810Stijl return (CMPLXF(cimagf(z), crealf(z))); 102226458Sdas} 103