pub fn primitive_float_atan2_rational<T>(y: &Rational, x: &Rational) -> TExpand description
Computes $\operatorname{atan2}(y,x)$, the angle of the point $(x,y)$ measured from the positive
$x$-axis, for Rationals, returning the result as a primitive float.
$$
f(y,x) = \operatorname{atan2}(y,x)+\varepsilon,
$$
where $|\varepsilon| < 2^{\lfloor\log_2 |\operatorname{atan2}(y,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 zero case below
is exact.
Special cases:
- $f(0,x)=0.0$ if $x \geq 0$, and $\pi$ if $x < 0$
- $f(y,0)=\pm\pi/2$, with the sign of $y$, for nonzero $y$
Overflow is not possible, since $|\operatorname{atan2}(y,x)| \leq \pi$. The result is subnormal, or zero, only for a positive $x$ with $|y/x|$ subnormal or smaller.
§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 max(y.significant_bits(), x.significant_bits()).
§Examples
use malachite_base::num::basic::traits::{NegativeOne, Zero};
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::atan2::primitive_float_atan2_rational;
use malachite_q::Rational;
assert_eq!(
NiceFloat(primitive_float_atan2_rational::<f64>(
&Rational::from(3),
&Rational::from(4)
)),
NiceFloat(0.6435011087932844)
);
assert_eq!(
NiceFloat(primitive_float_atan2_rational::<f32>(
&Rational::from(3),
&Rational::from(4)
)),
NiceFloat(0.6435011)
);
// a negative x with a zero y is half a turn
assert_eq!(
NiceFloat(primitive_float_atan2_rational::<f64>(
&Rational::ZERO,
&Rational::NEGATIVE_ONE
)),
NiceFloat(3.141592653589793)
);