Back to index

glibc  2.9
e_sinhl.c
Go to the documentation of this file.
00001 /*
00002  * ====================================================
00003  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00004  *
00005  * Developed at SunPro, a Sun Microsystems, Inc. business.
00006  * Permission to use, copy, modify, and distribute this
00007  * software is freely granted, provided that this notice
00008  * is preserved.
00009  * ====================================================
00010  */
00011 
00012 
00013 #if defined(LIBM_SCCS) && !defined(lint)
00014 static char rcsid[] = "$NetBSD: e_sinh.c,v 1.7 1995/05/10 20:46:13 jtc Exp $";
00015 #endif
00016 
00017 /* __ieee754_sinh(x)
00018  * Method :
00019  * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
00020  *     1. Replace x by |x| (sinh(-x) = -sinh(x)).
00021  *     2.
00022  *                                                E + E/(E+1)
00023  *         0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
00024  *                                                       2
00025  *
00026  *         22       <= x <= lnovft :  sinh(x) := exp(x)/2
00027  *         lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
00028  *         ln2ovft  <  x        :  sinh(x) := x*shuge (overflow)
00029  *
00030  * Special cases:
00031  *     sinh(x) is |x| if x is +INF, -INF, or NaN.
00032  *     only sinh(0)=0 is exact for finite x.
00033  */
00034 
00035 #include "math.h"
00036 #include "math_private.h"
00037 
00038 #ifdef __STDC__
00039 static const long double one = 1.0, shuge = 1.0e307;
00040 #else
00041 static long double one = 1.0, shuge = 1.0e307;
00042 #endif
00043 
00044 #ifdef __STDC__
00045        long double __ieee754_sinhl(long double x)
00046 #else
00047        long double __ieee754_sinhl(x)
00048        long double x;
00049 #endif
00050 {
00051        long double t,w,h;
00052        int64_t ix,jx;
00053 
00054     /* High word of |x|. */
00055        GET_LDOUBLE_MSW64(jx,x);
00056        ix = jx&0x7fffffffffffffffLL;
00057 
00058     /* x is INF or NaN */
00059        if(ix>=0x7ff0000000000000LL) return x+x;
00060 
00061        h = 0.5;
00062        if (jx<0) h = -h;
00063     /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
00064        if (ix < 0x4036000000000000LL) {   /* |x|<22 */
00065            if (ix<0x3e20000000000000LL)   /* |x|<2**-29 */
00066               if(shuge+x>one) return x;/* sinhl(tiny) = tiny with inexact */
00067            t = __expm1l(fabsl(x));
00068            if(ix<0x3ff0000000000000LL) return h*(2.0*t-t*t/(t+one));
00069            return h*(t+t/(t+one));
00070        }
00071 
00072     /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
00073        if (ix < 0x40862e42fefa39efLL)  return h*__ieee754_expl(fabsl(x));
00074 
00075     /* |x| in [log(maxdouble), overflowthresold] */
00076        if (ix <= 0x408633ce8fb9f87dLL) {
00077            w = __ieee754_expl(0.5*fabsl(x));
00078            t = h*w;
00079            return t*w;
00080        }
00081 
00082     /* |x| > overflowthresold, sinh(x) overflow */
00083        return x*shuge;
00084 }