Skip to main content

primitive_float_csch

Function primitive_float_csch 

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

Computes $\operatorname{csch} x$, the hyperbolic cosecant of a primitive float. The result is correctly rounded.

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

  • If $\operatorname{csch} x$ is zero or NaN, $\varepsilon$ may be ignored or assumed to be 0.
  • If $\operatorname{csch} x$ is nonzero, then $|\varepsilon| < 2^{\lfloor\log_2 |\operatorname{csch} 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(\text{NaN})=\text{NaN}$
  • $f(\infty)=0.0$
  • $f(-\infty)=-0.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$. An x of large magnitude gives a subnormal result, or underflows to $\pm0.0$.

§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::csch::primitive_float_csch;

assert!(primitive_float_csch(f32::NAN).is_nan());
assert_eq!(
    NiceFloat(primitive_float_csch(f32::INFINITY)),
    NiceFloat(0.0)
);
assert_eq!(
    NiceFloat(primitive_float_csch(-0.0f32)),
    NiceFloat(f32::NEGATIVE_INFINITY)
);
assert_eq!(
    NiceFloat(primitive_float_csch(1.0f32)),
    NiceFloat(0.8509181)
);
assert_eq!(
    NiceFloat(primitive_float_csch(-1.0f64)),
    NiceFloat(-0.8509181282393216)
);
assert_eq!(
    NiceFloat(primitive_float_csch(720.0f64)),
    NiceFloat(4.06446160484e-313)
);
assert_eq!(NiceFloat(primitive_float_csch(746.0f64)), NiceFloat(0.0));
assert_eq!(
    NiceFloat(primitive_float_csch(5.0e-309f64)),
    NiceFloat(f64::INFINITY)
);