pub fn primitive_float_sin_cos_rational<T>(x: &Rational) -> (T, T)where
Float: PartialOrd<T>,
for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,Expand description
Computes $\sin x$ and $\cos x$, the sine and cosine of a Rational, together, returning the
results as primitive floats.
The results are those of
primitive_float_sin_rational
and
primitive_float_cos_rational,
but the rounding of the input, the argument reduction, and most of the work are shared, so this
is faster than the two calls when both values are needed.
$$
f(x) = (\sin x+\varepsilon_s, \cos x+\varepsilon_c),
$$
where $|\varepsilon_s| < 2^{\lfloor\log_2 |\sin x|\rfloor-p}$ and $|\varepsilon_c| <
2^{\lfloor\log_2 |\cos x|\rfloor-p}$, and $p$ is the precision of the output (24 if T is a
f32 and 53 if T is a f64).
Special cases:
- $f(0)=(0,1)$
Overflow is not possible, since the results lie in $[-1, 1]$. The sine underflows, to a
subnormal or to zero, when $x$ is tiny, since $\sin x$ is then very close to $x$; the cosine is
never subnormal. See
primitive_float_sin_rational
and
primitive_float_cos_rational.
§Worst-case complexity
$T(m, e) = O((m+e) (\log (m+e))^2 \log\log (m+e))$
$M(m, e) = O((m+e) \log (m+e))$
where $T$ is time, $M$ is additional memory, $m$ is x.significant_bits(), and $e$ is
x.floor_log_base_2_abs() (taken as 0 when it is negative or $x = 0$): for $|x| \geq 2$ the
argument is reduced modulo $2\pi$, which needs $\pi$ to about $e$ bits.
§Examples
use malachite_base::num::basic::traits::Zero;
use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::sin_cos::primitive_float_sin_cos_rational;
use malachite_q::Rational;
let (s, c) = primitive_float_sin_cos_rational::<f64>(&Rational::ZERO);
assert_eq!(NiceFloat(s), NiceFloat(0.0));
assert_eq!(NiceFloat(c), NiceFloat(1.0));
let (s, c) = primitive_float_sin_cos_rational::<f64>(&Rational::from_unsigneds(1u8, 3));
assert_eq!(NiceFloat(s), NiceFloat(0.32719469679615226));
assert_eq!(NiceFloat(c), NiceFloat(0.9449569463147377));
let (s, c) = primitive_float_sin_cos_rational::<f32>(&Rational::from_unsigneds(1u8, 3));
assert_eq!(NiceFloat(s), NiceFloat(0.3271947));
assert_eq!(NiceFloat(c), NiceFloat(0.94495696));