pub fn primitive_float_cosh_rational<T>(x: &Rational) -> Twhere
Float: PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,Expand description
Computes $\cosh x$, the hyperbolic cosine of a Rational, returning the result as a primitive
float. The result is correctly rounded.
$$ f(x) = \cosh x+\varepsilon. $$
- If $\cosh x$ is infinite, $\varepsilon$ may be ignored or assumed to be 0.
- If $\cosh x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 \cosh x\rfloor-p}$, where $p$
is the precision of the output (24 if
Tis af32and 53 ifTis af64).
Special cases:
- $f(0)=1$
Overflow is possible: an x of large magnitude gives $\infty$. Since $\cosh x\geq 1$, the
result never underflows.
§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::cosh::primitive_float_cosh_rational;
use malachite_q::Rational;
assert_eq!(
NiceFloat(primitive_float_cosh_rational::<f64>(&Rational::ZERO)),
NiceFloat(1.0)
);
assert_eq!(
NiceFloat(primitive_float_cosh_rational::<f64>(
&Rational::from_unsigneds(1u8, 3)
)),
NiceFloat(1.0560718678299394)
);
assert_eq!(
NiceFloat(primitive_float_cosh_rational::<f64>(
&Rational::from_signeds(-1i8, 3)
)),
NiceFloat(1.0560718678299394)
);
assert_eq!(
NiceFloat(primitive_float_cosh_rational::<f64>(&Rational::from(10000))),
NiceFloat(f64::INFINITY)
);