amath  1.8.5
Simple command line calculator
sinh.c File Reference

Hyperbolic sine function. More...

#include "prim.h"
Include dependency graph for sinh.c:

Go to the source code of this file.

Functions

double sinh (double x)
 Hyperbolic sine function. More...
 

Variables

static const double one = 1.0
 
static const double shuge = 1.0e307
 

Detailed Description

Hyperbolic sine function.

Definition in file sinh.c.

Function Documentation

◆ sinh()

double sinh ( double  x)

Hyperbolic sine function.

Method
mathematically sinh(x) if defined to be (exp(x)-exp(-x))/2
 1. Replace x by |x| (sinh(-x) = -sinh(x)).
 2.
                                        E + E/(E+1)
     0        <= x <= 22     :  sinh(x) := -----------—, E=expm1(x)
                                2
     22       <= x <= lnovft :  sinh(x) := exp(x)/2
     lnovft   <= x <= ln2ovft:  sinh(x) := exp(x/2)/2 * exp(x/2)
     ln2ovft  <  x      :  sinh(x) := x*shuge (overflow)
Special cases
    sinh(x) is |x| if x is +INF, -INF, or NaN.
    only sinh(0)=0 is exact for finite x.

Definition at line 77 of file sinh.c.

References exp(), expm1(), fabs(), one, and shuge.

Referenced by cchsh(), ccot(), ccoth(), ccsc(), ccsch(), coth(), csch(), csec(), csech(), ctan(), ctanh(), and RealNumber::HypSine().

78 {
79  double t, w, h;
80  int32_t ix, jx;
81  uint32_t lx;
82 
83  // High word of |x|
84  GET_HIGH_WORD(jx, x);
85  ix = jx & 0x7FFFFFFF;
86 
87  // x is INF or NaN
88  if (ix >= 0x7FF00000)
89  {
90  return NAN;
91  }
92 
93  h = 0.5;
94  if (jx < 0)
95  h = -h;
96  /* |x| in [0,22], return sign(x)*0.5*(E+E/(E+1))) */
97  if (ix < 0x40360000)
98  { /* |x|<22 */
99  if (ix < 0x3E300000) /* |x|<2**-28 */
100  if (shuge + x > one)
101  return x; /* sinh(tiny) = tiny with inexact */
102  t = expm1(fabs(x));
103  if (ix < 0x3FF00000)
104  return h * (2.0 * t - t * t / (t + one));
105  return h * (t + t / (t + one));
106  }
107 
108  /* |x| in [22, log(maxdouble)] return 0.5*exp(|x|) */
109  if (ix < 0x40862E42)
110  return h * exp(fabs(x));
111 
112  /* |x| in [log(maxdouble), overflowthresold] */
113  lx = *((((*(uint32_t *)&one) >> 29)) + (uint32_t *)&x);
114  if (ix < 0x408633CE || ((ix == 0x408633CE) && (lx <= (uint32_t)0X8FB9F87D)))
115  {
116  w = exp(0.5 * fabs(x));
117  t = h * w;
118  return t * w;
119  }
120 
121  /* |x| > overflowthresold, sinh(x) overflow */
122  return x * shuge;
123 }
static const double one
Definition: sinh.c:53
#define GET_HIGH_WORD(i, d)
Get the more significant 32 bit int from a double.
Definition: prim.h:167
#define NAN
Definition: mathr.h:53
static const double shuge
Definition: sinh.c:54
double exp(double x)
Returns the exponential of x.
Definition: exp.c:138
double expm1(double x)
Definition: expm1.c:153
double fabs(double x)
Returns the absolute value of x.
Definition: fabs.c:51
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ one

const double one = 1.0
static

Definition at line 53 of file sinh.c.

Referenced by sinh().

◆ shuge

const double shuge = 1.0e307
static

Definition at line 54 of file sinh.c.

Referenced by sinh().