pub fn primitive_float_acos<T>(x: T) -> Twhere
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,Expand description
Computes $\arccos x$, the arccosine of a primitive float, 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(\text{NaN})=f(\pm\infty)=\text{NaN}$
- $f(x)=\text{NaN}$ for $|x|>1$
- $f(\pm0.0)=\pi/2$, rounded
- $f(1)=0.0$
- $f(-1)=\pi$, rounded
Overflow is not possible, since the result lies in $[0,\pi]$, and neither is underflow: the only input whose arccosine is zero is 1, where the result is exact.
§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::float::NiceFloat;
use malachite_float::float::arithmetic::acos::primitive_float_acos;
assert!(primitive_float_acos(f32::NAN).is_nan());
// the arccosine is NaN outside [-1, 1]
assert!(primitive_float_acos(2.0f32).is_nan());
assert_eq!(NiceFloat(primitive_float_acos(1.0f32)), NiceFloat(0.0));
assert_eq!(
NiceFloat(primitive_float_acos(0.5f32)),
NiceFloat(1.0471976)
);
assert_eq!(
NiceFloat(primitive_float_acos(0.5f64)),
NiceFloat(1.0471975511965979)
);
assert_eq!(
NiceFloat(primitive_float_acos(-1.0f64)),
NiceFloat(3.141592653589793)
);