Skip to main content

primitive_float_acoth

Function primitive_float_acoth 

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

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

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

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

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

§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::acoth::primitive_float_acoth;

assert!(primitive_float_acoth(f32::NAN).is_nan());
assert_eq!(
    NiceFloat(primitive_float_acoth(f32::INFINITY)),
    NiceFloat(0.0)
);
assert_eq!(
    NiceFloat(primitive_float_acoth(f32::NEGATIVE_INFINITY)),
    NiceFloat(-0.0)
);
assert!(primitive_float_acoth(0.0f32).is_nan());
assert_eq!(
    NiceFloat(primitive_float_acoth(1.0f32)),
    NiceFloat(f32::INFINITY)
);
assert_eq!(
    NiceFloat(primitive_float_acoth(-1.0f32)),
    NiceFloat(f32::NEGATIVE_INFINITY)
);
assert_eq!(
    NiceFloat(primitive_float_acoth(2.0f32)),
    NiceFloat(0.54930615)
);
assert_eq!(
    NiceFloat(primitive_float_acoth(2.0f64)),
    NiceFloat(0.5493061443340549)
);
assert_eq!(
    NiceFloat(primitive_float_acoth(-1.5f64)),
    NiceFloat(-0.8047189562170501)
);