pub fn primitive_float_cot_with_period<T>(x: T, u: u64) -> Twhere
Float: From<T> + PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,Expand description
Computes $\cot(2\pi x/u)$, the cotangent of a primitive float measured in $u$ths of a turn (so
that u = 360 is degrees).
$$ f(x,u) = \cot(2\pi x/u)+\varepsilon. $$
- If $x$ is not finite, $u=0$, or $x/u$ is a multiple of $1/8$, $\varepsilon$ may be ignored or assumed to be 0.
- Otherwise, $|\varepsilon| < 2^{\lfloor\log_2 |\cot(2\pi x/u)|\rfloor-p}$, where $p$ is the
precision of the output (24 if
Tis af32and 53 ifTis af64).
Special cases:
- $f(\text{NaN},u)=\text{NaN}$
- $f(\pm\infty,u)=\text{NaN}$
- $f(x,0)=\text{NaN}$
- $f(\pm0.0,u)=\pm\infty$
- If $x/u$ is a multiple of $1/2$, the cotangent has a pole there, and the result is exactly $\pm\infty$: the sine is a zero carrying the sign of $x$ and the cosine is $\pm1$, so the sign is that of $x$ at an even multiple and the opposite at an odd one.
- If $x/u$ is an odd multiple of $1/4$, the result is exactly $\pm0.0$, and if it is an odd multiple of $1/8$, exactly $\pm1$.
- If $x/u$ in lowest terms has denominator 3 or 6, the result is $\pm\sqrt3/3$, and if it has denominator 12, $\pm\sqrt3$.
Overflow happens at a pole, where the result is exactly $\pm\infty$, and for a tiny $x/u$, whose
cotangent is close to $u/(2\pi x)$: an f32 or f64 whose fraction of a turn is not a
multiple of $1/2$ is more than $2^{-66}$ of a turn away from one, so a cotangent that is not a
pole stays below $2^{64}$ unless the angle itself is tiny. Underflow happens only at an odd
quarter turn, where the result is exactly $\pm0.0$: a fraction of a turn that is not one is more
than $2^{-66}$ away from it, so the cotangent stays above $2^{-67}$.
§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_with_period;
assert!(primitive_float_cot_with_period(f32::NAN, 360).is_nan());
assert!(primitive_float_cot_with_period(f32::INFINITY, 360).is_nan());
assert!(primitive_float_cot_with_period(f32::NEGATIVE_INFINITY, 360).is_nan());
assert!(primitive_float_cot_with_period(1.0f32, 0).is_nan());
assert_eq!(
NiceFloat(primitive_float_cot_with_period(-0.0f32, 360)),
NiceFloat(f32::NEGATIVE_INFINITY)
);
// a quarter turn is exactly 0
assert_eq!(
NiceFloat(primitive_float_cot_with_period(90.0f32, 360)),
NiceFloat(0.0)
);
// a half turn is a pole
assert_eq!(
NiceFloat(primitive_float_cot_with_period(180.0f32, 360)),
NiceFloat(f32::NEGATIVE_INFINITY)
);
// a sixth of a turn: sqrt(3)/3
assert_eq!(
NiceFloat(primitive_float_cot_with_period(60.0f32, 360)),
NiceFloat(0.57735026)
);
// a twelfth of a turn: sqrt(3)
assert_eq!(
NiceFloat(primitive_float_cot_with_period(30.0f64, 360)),
NiceFloat(1.7320508075688772)
);
assert_eq!(
NiceFloat(primitive_float_cot_with_period(1.0f32, 7)),
NiceFloat(0.7974734)
);
assert_eq!(
NiceFloat(primitive_float_cot_with_period(1.0f64, 7)),
NiceFloat(0.7974733888824039)
);