Skip to main content

primitive_float_cos_pi

Function primitive_float_cos_pi 

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

Computes $\cos(\pi x)$, the cosine of a primitive float measured in half-turns.

This is primitive_float_cos_with_period with a period of 2: see primitive_float_cos_with_period for the error bound and the special cases, with $u = 2$. Half-integers give exactly $+0.0$ and integers exactly $\pm1$.

§Worst-case complexity

Constant time and additional memory.

§Examples

use malachite_base::num::float::NiceFloat;
use malachite_float::float::arithmetic::cos::primitive_float_cos_pi;

assert!(primitive_float_cos_pi(f32::NAN).is_nan());
assert_eq!(NiceFloat(primitive_float_cos_pi(0.5f32)), NiceFloat(0.0));
assert_eq!(NiceFloat(primitive_float_cos_pi(1.0f64)), NiceFloat(-1.0));
assert_eq!(
    NiceFloat(primitive_float_cos_pi(0.1f32)),
    NiceFloat(0.95105654)
);
assert_eq!(
    NiceFloat(primitive_float_cos_pi(0.1f64)),
    NiceFloat(0.9510565162951535)
);