support/fdlibm/e_sinh.c
author Jan Vrany <jan.vrany@fit.cvut.cz>
Wed, 16 Jan 2013 22:06:41 +0000
branchrefactoring-vmdata
changeset 1977 526315e0a801
parent 1818 2e5ed72e7dfd
child 2380 9195eccdcbd9
permissions -rw-r--r--
Fixed JavaNativeMethodImpl_OpenJDK6 class>>invoke:receiver:arguments:context:constructor:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
986
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
     1
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
     2
/* @(#)e_sinh.c 1.3 95/01/18 */
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
     3
/*
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
     4
 * ====================================================
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
     5
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
     6
 *
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
     7
 * Developed at SunSoft, a Sun Microsystems, Inc. business.
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
     8
 * Permission to use, copy, modify, and distribute this
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
     9
 * software is freely granted, provided that this notice 
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    10
 * is preserved.
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    11
 * ====================================================
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    12
 */
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    13
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    14
/* __ieee754_sinh(x)
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    15
 * Method : 
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    16
 * mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    17
 *	1. Replace x by |x| (sinh(-x) = -sinh(x)). 
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    18
 *	2. 
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    19
 *		                                    E + E/(E+1)
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    20
 *	    0        <= x <= 22     :  sinh(x) := --------------, E=expm1(x)
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    21
 *			       			        2
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    22
 *
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    23
 *	    22       <= x <= lnovft :  sinh(x) := exp(x)/2 
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    24
 *	    lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    25
 *	    ln2ovft  <  x	    :  sinh(x) := x*shuge (overflow)
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    26
 *
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    27
 * Special cases:
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    28
 *	sinh(x) is |x| if x is +INF, -INF, or NaN.
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    29
 *	only sinh(0)=0 is exact for finite x.
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    30
 */
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    31
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    32
#include "fdlibm.h"
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    33
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    34
#ifdef __STDC__
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    35
static const double one = 1.0, shuge = 1.0e307;
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    36
#else
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    37
static double one = 1.0, shuge = 1.0e307;
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    38
#endif
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    39
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    40
#ifdef __STDC__
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    41
	double __ieee754_sinh(double x)
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    42
#else
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    43
	double __ieee754_sinh(x)
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    44
	double x;
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    45
#endif
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    46
{	
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    47
	double t,w,h;
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    48
	int ix,jx;
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    49
	unsigned lx;
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    50
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    51
    /* High word of |x|. */
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    52
	jx = __HI(x);
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    53
	ix = jx&0x7fffffff;
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    54
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    55
    /* x is INF or NaN */
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    56
	if(ix>=0x7ff00000) return x+x;	
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    57
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    58
	h = 0.5;
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    59
	if (jx<0) h = -h;
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    60
    /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    61
	if (ix < 0x40360000) {		/* |x|<22 */
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    62
	    if (ix<0x3e300000) 		/* |x|<2**-28 */
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    63
		if(shuge+x>one) return x;/* sinh(tiny) = tiny with inexact */
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    64
	    t = expm1(fabs(x));
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    65
	    if(ix<0x3ff00000) return h*(2.0*t-t*t/(t+one));
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    66
	    return h*(t+t/(t+one));
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    67
	}
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    68
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    69
    /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    70
	if (ix < 0x40862E42)  return h*__ieee754_exp(fabs(x));
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    71
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    72
    /* |x| in [log(maxdouble), overflowthresold] */
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    73
	lx = *( (((*(unsigned*)&one)>>29)) + (unsigned*)&x);
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    74
	if (ix<0x408633CE || (ix==0x408633ce)&&(lx<=(unsigned)0x8fb9f87d)) {
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    75
	    w = __ieee754_exp(0.5*fabs(x));
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    76
	    t = h*w;
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    77
	    return t*w;
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    78
	}
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    79
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    80
    /* |x| > overflowthresold, sinh(x) overflow */
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    81
	return x*shuge;
a53b146a146d Added fdlibm for IEE754-style double arithmetics
vranyj1
parents:
diff changeset
    82
}