Skip to main content

primitive_float_csch_rational

Function primitive_float_csch_rational 

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

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

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

  • If $\operatorname{csch} x$ is zero, $\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(0)=\infty$

An x of magnitude below the reciprocal of the largest finite value 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

$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::Zero;
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::csch::primitive_float_csch_rational;
use malachite_q::Rational;

assert_eq!(
    NiceFloat(primitive_float_csch_rational::<f64>(&Rational::ZERO)),
    NiceFloat(f64::INFINITY)
);
assert_eq!(
    NiceFloat(primitive_float_csch_rational::<f64>(
        &Rational::from_unsigneds(1u8, 3)
    )),
    NiceFloat(2.9451562666948146)
);
assert_eq!(
    NiceFloat(primitive_float_csch_rational::<f64>(
        &Rational::from_signeds(-1i8, 3)
    )),
    NiceFloat(-2.9451562666948146)
);
assert_eq!(
    NiceFloat(primitive_float_csch_rational::<f64>(&Rational::from(10000))),
    NiceFloat(0.0)
);