pub fn primitive_float_asec<T>(x: T) -> Twhere
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,Expand description
Computes $\operatorname{asec} x$, the arcsecant of a primitive float, returning the result as a primitive float.
$$
f(x) = \operatorname{asec} x+\varepsilon,
$$
where $|\varepsilon| < 2^{\lfloor\log_2 |\operatorname{asec} 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})=\text{NaN}$
- $f(x)=\text{NaN}$ for $|x|<1$, including $\pm0.0$
- $f(\pm\infty)=\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 arcsecant 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::asec::primitive_float_asec;
assert!(primitive_float_asec(f32::NAN).is_nan());
// the arcsecant is NaN inside (-1, 1)
assert!(primitive_float_asec(0.5f32).is_nan());
assert_eq!(NiceFloat(primitive_float_asec(1.0f32)), NiceFloat(0.0));
assert_eq!(
NiceFloat(primitive_float_asec(2.0f32)),
NiceFloat(1.0471976)
);
assert_eq!(
NiceFloat(primitive_float_asec(2.0f64)),
NiceFloat(1.0471975511965979)
);
assert_eq!(
NiceFloat(primitive_float_asec(-1.0f64)),
NiceFloat(3.141592653589793)
);
// a huge input is a quarter turn
assert_eq!(
NiceFloat(primitive_float_asec(1.0e300f64)),
NiceFloat(1.5707963267948966)
);