pub fn primitive_float_cot<T>(x: T) -> Twhere
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,Expand description
Computes $\cot x$, the cotangent of a primitive float, correctly rounded. Neither the standard
library nor libm provides a cotangent.
$$ f(x) = \cot 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 |\cot 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)=\pm\infty$
Overflow is possible: the cotangent of a tiny $x$ is close to $1/x$, so an $x$ with $|x|$ below
about $2^{-128}$ has a cotangent beyond the largest f32, and one below about $2^{-1024}$
beyond the largest f64; the result is then $\pm\infty$. No f32 or f64 is close
enough to a nonzero multiple of $\pi$ for its cotangent to overflow that way, nor close enough
to an odd multiple of $\pi/2$ for it to underflow: the floats are spaced far more widely there
than either would take.
§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::cot::primitive_float_cot;
assert!(primitive_float_cot(f32::NAN).is_nan());
assert!(primitive_float_cot(f32::INFINITY).is_nan());
assert!(primitive_float_cot(f32::NEGATIVE_INFINITY).is_nan());
assert_eq!(
NiceFloat(primitive_float_cot(0.0f32)),
NiceFloat(f32::INFINITY)
);
assert_eq!(
NiceFloat(primitive_float_cot(-0.0f32)),
NiceFloat(f32::NEGATIVE_INFINITY)
);
assert_eq!(
NiceFloat(primitive_float_cot(1.0f32)),
NiceFloat(0.64209265)
);
assert_eq!(
NiceFloat(primitive_float_cot(1.0f64)),
NiceFloat(0.6420926159343308)
);