Skip to main content

primitive_float_atanh_rational

Function primitive_float_atanh_rational 

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

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

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

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

Overflow is not possible for $|x|<1$. Underflow is: an x of small enough magnitude gives 0.0 or -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, Two, Zero};
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::atanh::primitive_float_atanh_rational;
use malachite_q::Rational;

assert_eq!(
    NiceFloat(primitive_float_atanh_rational::<f64>(&Rational::ZERO)),
    NiceFloat(0.0)
);
assert_eq!(
    NiceFloat(primitive_float_atanh_rational::<f64>(&Rational::ONE)),
    NiceFloat(f64::INFINITY)
);
assert!(primitive_float_atanh_rational::<f64>(&Rational::TWO).is_nan());
assert_eq!(
    NiceFloat(primitive_float_atanh_rational::<f64>(&Rational::ONE_HALF)),
    NiceFloat(0.5493061443340549)
);
assert_eq!(
    NiceFloat(primitive_float_atanh_rational::<f64>(
        &Rational::from_unsigneds(1u8, 3)
    )),
    NiceFloat(0.34657359027997264)
);