Skip to main content

Module hyper

Module hyper 

Source
Expand description

Hyperbolic functions, built from the cancellation-free exp_m1 / ln_1p primitives:

  • sinh(x) = (exp_m1(x) - exp_m1(-x)) / 2
  • cosh(x) = (exp_m1(x) + exp_m1(-x)) / 2 + 1
  • tanh(x) = exp_m1(2x) / (exp_m1(2x) + 2)
  • asinh(x) = sign(x) · ln_1p(|x| + x²/(sqrt(x²+1)+1))
  • acosh(x) = ln_1p((x-1) + sqrt((x-1)(x+1))) (x ≥ 1)
  • atanh(x) = ln_1p(2x/(1-x)) / 2 (|x| < 1)

The exp_m1 / ln_1p forms avoid the catastrophic cancellation that the naive (exp(x)-exp(-x))/2 and ln(1+…) formulas suffer for small arguments. Special values follow IEEE 754: infinities are values (not errors) for the forward functions and asinh; acosh(x<1) and atanh(|x|>1) are domain errors.