pub fn primitive_float_atan2_with_period<T>(y: T, x: T, u: u64) -> TExpand description
Computes $\operatorname{atan2}(y,x)u/(2\pi)$, the angle of the point $(x,y)$ measured from the
positive $x$-axis in $u$ths of a turn (so that u = 360 gives degrees), for primitive floats.
$$
f(y,x,u) = \operatorname{atan2}(y,x)u/(2\pi)+\varepsilon,
$$
where $|\varepsilon| < 2^{\lfloor\log_2 |\operatorname{atan2}(y,x)u/(2\pi)|\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 when the output can hold them.
Special cases, in which the sign of a zero argument selects the quadrant:
- $f(\text{NaN},x,u)=f(y,\text{NaN},u)=\text{NaN}$
- $f(\pm\infty,+\infty,u)=\pm u/8$ and $f(\pm\infty,-\infty,u)=\pm3u/8$
- $f(\pm\infty,x,u)=\pm u/4$ for finite $x$
- $f(y,+\infty,u)=\pm0.0$ and $f(y,-\infty,u)=\pm u/2$, with the sign of $y$
- $f(\pm0.0,x,u)=\pm0.0$ if $x$ is positive or $+0.0$, and $\pm u/2$ otherwise
- $f(y,\pm0.0,u)=\pm u/4$, with the sign of $y$, for nonzero $y$
- $f(\pm x,x,u)=\pm u/8$ for positive $x$, and $\pm3u/8$ for negative $x$
- $f(y,x,0)=\pm0.0$, with the sign of $y$
Overflow is not possible, since $|f(y,x,u)| \leq u/2 < 2^{63}$. The result is subnormal, or zero, only for a positive $x$ with $|y/x|$ tiny and $u$ small.
§Worst-case complexity
Constant time and additional memory.
§Examples
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::atan2::primitive_float_atan2_with_period;
assert!(primitive_float_atan2_with_period(f32::NAN, 1.0, 360).is_nan());
// the first quadrant's diagonal is an eighth of a turn
assert_eq!(
NiceFloat(primitive_float_atan2_with_period(1.0f32, 1.0, 360)),
NiceFloat(45.0)
);
// the second quadrant's diagonal is three eighths
assert_eq!(
NiceFloat(primitive_float_atan2_with_period(1.0f32, -1.0, 360)),
NiceFloat(135.0)
);
assert_eq!(
NiceFloat(primitive_float_atan2_with_period(3.0f64, 4.0, 360)),
NiceFloat(36.86989764584402)
);
// a negative x with a zero y is half a turn
assert_eq!(
NiceFloat(primitive_float_atan2_with_period(0.0f64, -1.0, 360)),
NiceFloat(180.0)
);