1425bb815Sopenharmony_ci/* Copyright JS Foundation and other contributors, http://js.foundation 2425bb815Sopenharmony_ci * 3425bb815Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4425bb815Sopenharmony_ci * you may not use this file except in compliance with the License. 5425bb815Sopenharmony_ci * You may obtain a copy of the License at 6425bb815Sopenharmony_ci * 7425bb815Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8425bb815Sopenharmony_ci * 9425bb815Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10425bb815Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS 11425bb815Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12425bb815Sopenharmony_ci * See the License for the specific language governing permissions and 13425bb815Sopenharmony_ci * limitations under the License. 14425bb815Sopenharmony_ci * 15425bb815Sopenharmony_ci * This file is based on work under the following copyright and permission 16425bb815Sopenharmony_ci * notice: 17425bb815Sopenharmony_ci * 18425bb815Sopenharmony_ci * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 19425bb815Sopenharmony_ci * 20425bb815Sopenharmony_ci * Developed at SunSoft, a Sun Microsystems, Inc. business. 21425bb815Sopenharmony_ci * Permission to use, copy, modify, and distribute this 22425bb815Sopenharmony_ci * software is freely granted, provided that this notice 23425bb815Sopenharmony_ci * is preserved. 24425bb815Sopenharmony_ci * 25425bb815Sopenharmony_ci * @(#)e_sinh.c 1.3 95/01/18 26425bb815Sopenharmony_ci */ 27425bb815Sopenharmony_ci 28425bb815Sopenharmony_ci#include "jerry-libm-internal.h" 29425bb815Sopenharmony_ci 30425bb815Sopenharmony_ci/* __sinh(x) 31425bb815Sopenharmony_ci * Method: 32425bb815Sopenharmony_ci * mathematically sinh(x) if defined to be (exp(x) - exp(-x)) / 2 33425bb815Sopenharmony_ci * 1. Replace x by |x| (sinh(-x) = -sinh(x)). 34425bb815Sopenharmony_ci * 2. 35425bb815Sopenharmony_ci * E + E/(E+1) 36425bb815Sopenharmony_ci * 0 <= x <= 22 : sinh(x) := -------------, E = expm1(x) 37425bb815Sopenharmony_ci * 2 38425bb815Sopenharmony_ci * 39425bb815Sopenharmony_ci * 22 <= x <= lnovft : sinh(x) := exp(x) / 2 40425bb815Sopenharmony_ci * lnovft <= x <= ln2ovft: sinh(x) := exp(x / 2) / 2 * exp(x / 2) 41425bb815Sopenharmony_ci * ln2ovft < x : sinh(x) := x * shuge (overflow) 42425bb815Sopenharmony_ci * 43425bb815Sopenharmony_ci * Special cases: 44425bb815Sopenharmony_ci * sinh(x) is |x| if x is +INF, -INF, or NaN. 45425bb815Sopenharmony_ci * only sinh(0) = 0 is exact for finite x. 46425bb815Sopenharmony_ci */ 47425bb815Sopenharmony_ci 48425bb815Sopenharmony_ci#define one 1.0 49425bb815Sopenharmony_ci#define half 0.5 50425bb815Sopenharmony_ci#define shuge 1.0e307 51425bb815Sopenharmony_ci 52425bb815Sopenharmony_cidouble 53425bb815Sopenharmony_cisinh (double x) 54425bb815Sopenharmony_ci{ 55425bb815Sopenharmony_ci double t, w, h; 56425bb815Sopenharmony_ci int ix, jx; 57425bb815Sopenharmony_ci unsigned lx; 58425bb815Sopenharmony_ci 59425bb815Sopenharmony_ci /* High word of |x|. */ 60425bb815Sopenharmony_ci jx = __HI (x); 61425bb815Sopenharmony_ci ix = jx & 0x7fffffff; 62425bb815Sopenharmony_ci 63425bb815Sopenharmony_ci /* x is INF or NaN */ 64425bb815Sopenharmony_ci if (ix >= 0x7ff00000) 65425bb815Sopenharmony_ci { 66425bb815Sopenharmony_ci return x + x; 67425bb815Sopenharmony_ci } 68425bb815Sopenharmony_ci 69425bb815Sopenharmony_ci h = 0.5; 70425bb815Sopenharmony_ci if (jx < 0) 71425bb815Sopenharmony_ci { 72425bb815Sopenharmony_ci h = -h; 73425bb815Sopenharmony_ci } 74425bb815Sopenharmony_ci /* |x| in [0,22], return sign(x) * 0.5 * (E + E / (E + 1))) */ 75425bb815Sopenharmony_ci if (ix < 0x40360000) 76425bb815Sopenharmony_ci { 77425bb815Sopenharmony_ci /* |x| < 22 */ 78425bb815Sopenharmony_ci if (ix < 0x3e300000) 79425bb815Sopenharmony_ci { 80425bb815Sopenharmony_ci /* |x| < 2**-28 */ 81425bb815Sopenharmony_ci if (shuge + x > one) 82425bb815Sopenharmony_ci { 83425bb815Sopenharmony_ci /* sinh(tiny) = tiny with inexact */ 84425bb815Sopenharmony_ci return x; 85425bb815Sopenharmony_ci } 86425bb815Sopenharmony_ci } 87425bb815Sopenharmony_ci t = expm1 (fabs (x)); 88425bb815Sopenharmony_ci if (ix < 0x3ff00000) 89425bb815Sopenharmony_ci { 90425bb815Sopenharmony_ci return h * (2.0 * t - t * t / (t + one)); 91425bb815Sopenharmony_ci } 92425bb815Sopenharmony_ci return h * (t + t / (t + one)); 93425bb815Sopenharmony_ci } 94425bb815Sopenharmony_ci 95425bb815Sopenharmony_ci /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */ 96425bb815Sopenharmony_ci if (ix < 0x40862E42) 97425bb815Sopenharmony_ci { 98425bb815Sopenharmony_ci return h * exp (fabs (x)); 99425bb815Sopenharmony_ci } 100425bb815Sopenharmony_ci /* |x| in [log(maxdouble), overflowthresold] */ 101425bb815Sopenharmony_ci lx = ((1 >> 29) + (unsigned int) x); 102425bb815Sopenharmony_ci if (ix < 0x408633CE || ((ix == 0x408633ce) && (lx <= (unsigned) 0x8fb9f87d))) 103425bb815Sopenharmony_ci { 104425bb815Sopenharmony_ci w = exp (0.5 * fabs (x)); 105425bb815Sopenharmony_ci t = h * w; 106425bb815Sopenharmony_ci return t * w; 107425bb815Sopenharmony_ci } 108425bb815Sopenharmony_ci 109425bb815Sopenharmony_ci /* |x| > overflowthresold, sinh(x) overflow */ 110425bb815Sopenharmony_ci return x * shuge; 111425bb815Sopenharmony_ci} /* sinh */ 112425bb815Sopenharmony_ci 113425bb815Sopenharmony_ci#undef one 114425bb815Sopenharmony_ci#undef half 115425bb815Sopenharmony_ci#undef huge 116