pub fn primitive_float_sec<T>(x: T) -> Twhere
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,Expand description
Computes $\sec x$, the secant of a primitive float, correctly rounded. Neither the standard
library nor libm provides a secant.
$$ f(x) = \sec x+\varepsilon. $$
- If $x$ is not finite, $\varepsilon$ may be ignored or assumed to be 0.
- If $x$ is finite, then $|\varepsilon| < 2^{\lfloor\log_2 |\sec x|\rfloor-p}$, where $p$ is the
precision of the output (24 if
Tis af32and 53 ifTis af64).
Special cases:
- $f(\text{NaN})=\text{NaN}$
- $f(\pm\infty)=\text{NaN}$
- $f(\pm0.0)=1.0$
Overflow is not possible: no f32 or f64 is close enough to an odd multiple of $\pi/2$
for its secant to exceed the largest finite value (the largest secant of an f64, like the
largest tangent, is below $2^{55}$). The result is never subnormal, since $|\sec x| \geq 1$.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::basic::traits::NegativeInfinity;
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::sec::primitive_float_sec;
assert!(primitive_float_sec(f32::NAN).is_nan());
assert!(primitive_float_sec(f32::INFINITY).is_nan());
assert!(primitive_float_sec(f32::NEGATIVE_INFINITY).is_nan());
assert_eq!(NiceFloat(primitive_float_sec(0.0f32)), NiceFloat(1.0));
assert_eq!(NiceFloat(primitive_float_sec(-0.0f32)), NiceFloat(1.0));
assert_eq!(NiceFloat(primitive_float_sec(1.0f32)), NiceFloat(1.8508158));
assert_eq!(
NiceFloat(primitive_float_sec(1.0f64)),
NiceFloat(1.8508157176809257)
);