Skip to main content

primitive_float_asinh

Function primitive_float_asinh 

Source
pub fn primitive_float_asinh<T>(x: T) -> T
where Float: From<T> + PartialOrd<T>, for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,
Expand description

Computes $\operatorname{asinh} x$, the inverse hyperbolic sine of a primitive float. Using this function is more accurate than using the default asinh function or the one provided by libm.

$$ f(x) = \operatorname{asinh} x+\varepsilon. $$

  • If $x$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $x$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |\operatorname{asinh} x|\rfloor-p}$, where $p$ is the precision of the output (24 if T is a f32 and 53 if T is a f64).

Special cases:

  • $f(\text{NaN})=\text{NaN}$
  • $f(\pm\infty)=\pm\infty$
  • $f(\pm0.0)=\pm0.0$

Overflow is not possible, since $|\operatorname{asinh} x| \leq |x|$. The result is subnormal only when $x$ is, and then it is $x$ itself, since $|\operatorname{asinh} x - x| < |x|^3/6$.

§Worst-case complexity

Constant time and additional memory.

§Examples

use malachite_base::num::basic::traits::NegativeInfinity;
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::asinh::primitive_float_asinh;

assert!(primitive_float_asinh(f32::NAN).is_nan());
assert_eq!(
    NiceFloat(primitive_float_asinh(f32::INFINITY)),
    NiceFloat(f32::INFINITY)
);
assert_eq!(
    NiceFloat(primitive_float_asinh(f32::NEGATIVE_INFINITY)),
    NiceFloat(f32::NEGATIVE_INFINITY)
);
assert_eq!(NiceFloat(primitive_float_asinh(0.0f32)), NiceFloat(0.0));
assert_eq!(NiceFloat(primitive_float_asinh(-0.0f32)), NiceFloat(-0.0));
assert_eq!(
    NiceFloat(primitive_float_asinh(1.0f32)),
    NiceFloat(0.8813736)
);
assert_eq!(
    NiceFloat(primitive_float_asinh(1.0f64)),
    NiceFloat(0.881373587019543)
);