tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

e_sinh.cpp (2017B)


      1 /* @(#)e_sinh.c 1.3 95/01/18 */
      2 /*
      3 * ====================================================
      4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
      5 *
      6 * Developed at SunSoft, a Sun Microsystems, Inc. business.
      7 * Permission to use, copy, modify, and distribute this
      8 * software is freely granted, provided that this notice 
      9 * is preserved.
     10 * ====================================================
     11 */
     12 
     13 //#include <sys/cdefs.h>
     14 //__FBSDID("$FreeBSD$");
     15 
     16 /* __ieee754_sinh(x)
     17 * Method : 
     18 * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
     19 *	1. Replace x by |x| (sinh(-x) = -sinh(x)). 
     20 *	2. 
     21 *		                                    E + E/(E+1)
     22 *	    0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
     23 *			       			        2
     24 *
     25 *	    22       <= x <= lnovft :  sinh(x) := exp(x)/2 
     26 *	    lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
     27 *	    ln2ovft  <  x	    :  sinh(x) := x*shuge (overflow)
     28 *
     29 * Special cases:
     30 *	sinh(x) is |x| if x is +INF, -INF, or NaN.
     31 *	only sinh(0)=0 is exact for finite x.
     32 */
     33 
     34 #include <float.h>
     35 #include <math.h>
     36 
     37 #include "math_private.h"
     38 
     39 static const double one = 1.0, shuge = 1.0e307;
     40 
     41 double
     42 __ieee754_sinh(double x)
     43 {
     44 double t,h;
     45 int32_t ix,jx;
     46 
     47    /* High word of |x|. */
     48 GET_HIGH_WORD(jx,x);
     49 ix = jx&0x7fffffff;
     50 
     51    /* x is INF or NaN */
     52 if(ix>=0x7ff00000) return x+x;	
     53 
     54 h = 0.5;
     55 if (jx<0) h = -h;
     56    /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
     57 if (ix < 0x40360000) {		/* |x|<22 */
     58     if (ix<0x3e300000) 		/* |x|<2**-28 */
     59 	if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
     60     t = expm1(fabs(x));
     61     if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
     62     return h*(t+t/(t+one));
     63 }
     64 
     65    /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
     66 if (ix < 0x40862E42)  return h*__ieee754_exp(fabs(x));
     67 
     68    /* |x| in [log(maxdouble), overflowthresold] */
     69 if (ix<=0x408633CE)
     70     return h*2.0*__ldexp_exp(fabs(x), -1);
     71 
     72    /* |x| > overflowthresold, sinh(x) overflow */
     73 return x*shuge;
     74 }