Skip to main content

primitive_float_coth

Function primitive_float_coth 

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

Computes $\coth x$, the hyperbolic cotangent of a primitive float. The result is correctly rounded.

$$ f(x) = \coth x+\varepsilon. $$

  • If $\coth x$ is infinite or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\coth x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\coth 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)=1.0$
  • $f(-\infty)=-1.0$
  • $f(0.0)=\infty$
  • $f(-0.0)=-\infty$

An x of magnitude below the reciprocal of the largest finite value, such as a subnormal, gives a result that overflows to $\pm\infty$. Underflow is not possible, since $|\coth x| > 1$.

§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::coth::primitive_float_coth;

assert!(primitive_float_coth(f32::NAN).is_nan());
assert_eq!(
    NiceFloat(primitive_float_coth(f32::INFINITY)),
    NiceFloat(1.0)
);
assert_eq!(
    NiceFloat(primitive_float_coth(-0.0f32)),
    NiceFloat(f32::NEGATIVE_INFINITY)
);
assert_eq!(
    NiceFloat(primitive_float_coth(1.0f32)),
    NiceFloat(1.3130352)
);
assert_eq!(
    NiceFloat(primitive_float_coth(-1.0f64)),
    NiceFloat(-1.3130352854993312)
);
assert_eq!(
    NiceFloat(primitive_float_coth(10.0f64)),
    NiceFloat(1.0000000041223072)
);
assert_eq!(NiceFloat(primitive_float_coth(20.0f64)), NiceFloat(1.0));
assert_eq!(
    NiceFloat(primitive_float_coth(5.0e-309f64)),
    NiceFloat(f64::INFINITY)
);