Skip to main content

primitive_float_acosh

Function primitive_float_acosh 

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

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

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

  • If $\operatorname{acosh} x$ is infinite, zero, or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\operatorname{acosh} x$ is finite and nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 \operatorname{acosh} 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(\infty)=\infty$
  • $f(-\infty)=\text{NaN}$
  • $f(\pm0.0)=\text{NaN}$
  • $f(1)=0.0$
  • $f(x)=\text{NaN}$ if $x<1$

Overflow and underflow are not possible: the result is less than $\ln 2x$, and for $x>1$ it is at least $\operatorname{acosh}(1+2^{1-p})$, far above the subnormal range.

§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::acosh::primitive_float_acosh;

assert!(primitive_float_acosh(f32::NAN).is_nan());
assert_eq!(
    NiceFloat(primitive_float_acosh(f32::INFINITY)),
    NiceFloat(f32::INFINITY)
);
assert!(primitive_float_acosh(f32::NEGATIVE_INFINITY).is_nan());
assert!(primitive_float_acosh(0.0f32).is_nan());
assert!(primitive_float_acosh(-0.0f32).is_nan());
assert_eq!(NiceFloat(primitive_float_acosh(1.0f32)), NiceFloat(0.0));
assert_eq!(
    NiceFloat(primitive_float_acosh(2.0f32)),
    NiceFloat(1.316958)
);
assert_eq!(
    NiceFloat(primitive_float_acosh(2.0f64)),
    NiceFloat(1.3169578969248168)
);