pub fn primitive_float_acos_rational<T>(x: &Rational) -> TExpand description
Computes $\arccos x$, the arccosine of a Rational, returning the result as a primitive
float.
$$
f(x) = \arccos x+\varepsilon,
$$
where $|\varepsilon| < 2^{\lfloor\log_2 |\arccos x|\rfloor-p}$ and $p$ is the precision of the
output (24 if T is a f32 and 53 if T is a f64); the special cases below are exact.
Special cases:
- $f(x)=\text{NaN}$ for $|x|>1$
- $f(0)=\pi/2$, rounded
- $f(1)=0.0$
- $f(-1)=\pi$, rounded
Overflow is not possible, since the result lies in $[0,\pi]$. The result is subnormal, or zero, only for an $x$ within $2^{-2^{31}}$ of 1.
§Worst-case complexity
$T(m) = O(m \log m \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::{One, Two};
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::acos::primitive_float_acos_rational;
use malachite_q::Rational;
// the arccosine is NaN outside [-1, 1]
assert!(primitive_float_acos_rational::<f64>(&Rational::TWO).is_nan());
assert_eq!(
NiceFloat(primitive_float_acos_rational::<f64>(&Rational::ONE)),
NiceFloat(0.0)
);
assert_eq!(
NiceFloat(primitive_float_acos_rational::<f64>(
&Rational::from_unsigneds(3u8, 5)
)),
NiceFloat(0.9272952180016122)
);
assert_eq!(
NiceFloat(primitive_float_acos_rational::<f32>(
&Rational::from_unsigneds(3u8, 5)
)),
NiceFloat(0.9272952)
);