Path: blob/master/src/java.base/share/native/libfdlibm/e_sinh.c
41149 views
/*1* Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/* __ieee754_sinh(x)26* Method :27* mathematically sinh(x) if defined to be (exp(x)-exp(-x))/228* 1. Replace x by |x| (sinh(-x) = -sinh(x)).29* 2.30* E + E/(E+1)31* 0 <= x <= 22 : sinh(x) := --------------, E=expm1(x)32* 233*34* 22 <= x <= lnovft : sinh(x) := exp(x)/235* lnovft <= x <= ln2ovft: sinh(x) := exp(x/2)/2 * exp(x/2)36* ln2ovft < x : sinh(x) := x*shuge (overflow)37*38* Special cases:39* sinh(x) is |x| if x is +INF, -INF, or NaN.40* only sinh(0)=0 is exact for finite x.41*/4243#include "fdlibm.h"4445#ifdef __STDC__46static const double one = 1.0, shuge = 1.0e307;47#else48static double one = 1.0, shuge = 1.0e307;49#endif5051#ifdef __STDC__52double __ieee754_sinh(double x)53#else54double __ieee754_sinh(x)55double x;56#endif57{58double t,w,h;59int ix,jx;60unsigned lx;6162/* High word of |x|. */63jx = __HI(x);64ix = jx&0x7fffffff;6566/* x is INF or NaN */67if(ix>=0x7ff00000) return x+x;6869h = 0.5;70if (jx<0) h = -h;71/* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */72if (ix < 0x40360000) { /* |x|<22 */73if (ix<0x3e300000) /* |x|<2**-28 */74if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */75t = expm1(fabs(x));76if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));77return h*(t+t/(t+one));78}7980/* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */81if (ix < 0x40862E42) return h*__ieee754_exp(fabs(x));8283/* |x| in [log(maxdouble), overflowthresold] */84lx = *( (((*(unsigned*)&one)>>29)) + (unsigned*)&x);85if (ix<0x408633CE || ((ix==0x408633ce)&&(lx<=(unsigned)0x8fb9f87d))) {86w = __ieee754_exp(0.5*fabs(x));87t = h*w;88return t*w;89}9091/* |x| > overflowthresold, sinh(x) overflow */92return x*shuge;93}949596