Skip to main content

primitive_float_acosh_rational

Function primitive_float_acosh_rational 

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

Computes $\operatorname{acosh} x$, the inverse hyperbolic cosine of a Rational, returning the result as a primitive float. The result is correctly rounded.

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

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

Special cases:

  • $f(1)=0.0$
  • $f(x)=\text{NaN}$ if $x<1$

Overflow is not possible. Underflow is: an x close enough to 1 gives 0.0.

§Worst-case complexity

$T(m) = O(m (\log m)^2 \log\log m)$

$M(m) = O(m \log m)$

where $T$ is time, $M$ is additional memory, and $m$ is x.significant_bits().

§Examples

use malachite_base::num::basic::traits::{One, OneHalf};
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::acosh::primitive_float_acosh_rational;
use malachite_q::Rational;

assert!(primitive_float_acosh_rational::<f64>(&Rational::ONE_HALF).is_nan());
assert_eq!(
    NiceFloat(primitive_float_acosh_rational::<f64>(&Rational::ONE)),
    NiceFloat(0.0)
);
assert_eq!(
    NiceFloat(primitive_float_acosh_rational::<f64>(
        &Rational::from_unsigneds(3u8, 2)
    )),
    NiceFloat(0.9624236501192069)
);
assert_eq!(
    NiceFloat(primitive_float_acosh_rational::<f64>(
        &Rational::from_unsigneds(22u8, 7)
    )),
    NiceFloat(1.8119507608214136)
);