Skip to main content

primitive_float_sin_cos_pi_rational

Function primitive_float_sin_cos_pi_rational 

Source
pub fn primitive_float_sin_cos_pi_rational<T>(x: &Rational) -> (T, T)
where Float: PartialOrd<T>, for<'a> T: ExactFrom<&'a Float> + RoundingFrom<&'a Float> + PrimitiveFloat,
Expand description

Computes $\sin(\pi x)$ and $\cos(\pi x)$, the sine and cosine of a Rational measured in half-turns, together, returning the results as primitive floats.

This is primitive_float_sin_cos_with_period_rational with a period of 2: see primitive_float_sin_cos_with_period_rational for the error bounds, the special cases, and the complexity, with $u = 2$.

§Worst-case complexity

$T(m) = O(m (\log m)^2 \log\log m)$

$M(m) = O(m \log m)$

where $T$ is time, $M$ is additional memory, and $m$ is x.significant_bits().

§Examples

use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::sin_cos::primitive_float_sin_cos_pi_rational;
use malachite_q::Rational;

// a sixth of a half-turn: exactly 1/2, and sqrt(3)/2
let (s, c) = primitive_float_sin_cos_pi_rational::<f64>(&Rational::from_unsigneds(1u8, 6));
assert_eq!(NiceFloat(s), NiceFloat(0.5));
assert_eq!(NiceFloat(c), NiceFloat(0.8660254037844386));

let (s, c) = primitive_float_sin_cos_pi_rational::<f64>(&Rational::from_unsigneds(1u8, 7));
assert_eq!(NiceFloat(s), NiceFloat(0.4338837391175581));
assert_eq!(NiceFloat(c), NiceFloat(0.9009688679024191));