amath  1.8.5
Simple command line calculator
atanh.c File Reference

Inverse hyperbolic tangent function. More...

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

Go to the source code of this file.

Functions

double atanh (double x)
 Inverse hyperbolic tangent function. More...
 

Variables

static const double one = 1.0
 
static const double huge = 1e300
 
static double zero = 0.0
 

Detailed Description

Inverse hyperbolic tangent function.

Definition in file atanh.c.

Function Documentation

◆ atanh()

double atanh ( double  x)

Inverse hyperbolic tangent function.

Method
1.Reduced x to positive by atanh(-x) = -atanh(x)
2.For x>=0.5
              1               2x                         x
  atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------)
              2             1 - x                      1 - x

  For x<0.5
  atanh(x) = 0.5*log1p(2x+2x*x/(1-x))
Special cases
    atanh(x) is NaN if |x| > 1
    atanh(NaN) is that NaN
    atanh(+-1) is +-INF

Definition at line 72 of file atanh.c.

References huge, log1p(), one, and zero.

Referenced by RealNumber::HypArcTangent().

73 {
74  double t;
75  int32_t hx, ix;
76  uint32_t lx;
77  GET_HIGH_WORD(hx, x);
78  GET_LOW_WORD(lx, x);
79  ix = hx & 0x7FFFFFFF;
80 
81  // |x| > 1
82  if ((ix | ((lx | (-lx)) >> 31)) > 0x3FF00000)
83  {
84  return NAN;
85  }
86 
87  if (ix == 0x3FF00000)
88  return x / zero;
89  if (ix < 0x3E300000 && (huge + x) > zero)
90  return x; /* x<2**-28 */
91  SET_HIGH_WORD(x, ix); /* x <- |x| */
92  if (ix < 0x3FE00000)
93  { /* x < 0.5 */
94  t = x + x;
95  t = 0.5 * log1p(t + t * x / (one - x));
96  }
97  else
98  t = 0.5 * log1p((x + x) / (one - x));
99 
100  if (hx >= 0)
101  {
102  return t;
103  }
104 
105  return -t;
106 }
#define GET_HIGH_WORD(i, d)
Get the more significant 32 bit int from a double.
Definition: prim.h:167
#define GET_LOW_WORD(i, d)
Get the less significant 32 bit int from a double.
Definition: prim.h:177
static double zero
Definition: atanh.c:49
#define NAN
Definition: mathr.h:53
static const double huge
Definition: atanh.c:48
static const double one
Definition: atanh.c:48
double log1p(double x)
Definition: log1p.c:122
#define SET_HIGH_WORD(d, v)
Set the more significant 32 bits of a double from an int.
Definition: prim.h:198
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ huge

const double huge = 1e300
static

Definition at line 48 of file atanh.c.

Referenced by atanh().

◆ one

const double one = 1.0
static

Definition at line 48 of file atanh.c.

Referenced by atanh().

◆ zero

double zero = 0.0
static

Definition at line 49 of file atanh.c.

Referenced by atanh().