From ada25b96dac5c091bb25ed910eb697b60e302af8 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Wed, 12 May 2021 17:55:17 -0700 Subject: [PATCH] add sin_cos_pi_f64 --- src/algorithms/trig_pi.rs | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/algorithms/trig_pi.rs b/src/algorithms/trig_pi.rs index b2a870f..93d2efc 100644 --- a/src/algorithms/trig_pi.rs +++ b/src/algorithms/trig_pi.rs @@ -230,6 +230,27 @@ pub fn cos_pi_f32(ctx: Ctx, x: Ctx::VecF32) -> Ctx::VecF32 { sin_cos_pi_f32(ctx, x).1 } +/// computes `(sin(pi * x), cos(pi * x))` +/// not guaranteed to give correct sign for zero results +/// has an error of up to 2ULP +pub fn sin_cos_pi_f64(ctx: Ctx, x: Ctx::VecF64) -> (Ctx::VecF64, Ctx::VecF64) { + sin_cos_pi_impl(ctx, x, sin_pi_kernel_f64, cos_pi_kernel_f64) +} + +/// computes `sin(pi * x)` +/// not guaranteed to give correct sign for zero results +/// has an error of up to 2ULP +pub fn sin_pi_f64(ctx: Ctx, x: Ctx::VecF64) -> Ctx::VecF64 { + sin_cos_pi_f64(ctx, x).0 +} + +/// computes `cos(pi * x)` +/// not guaranteed to give correct sign for zero results +/// has an error of up to 2ULP +pub fn cos_pi_f64(ctx: Ctx, x: Ctx::VecF64) -> Ctx::VecF64 { + sin_cos_pi_f64(ctx, x).1 +} + #[cfg(test)] mod tests { use super::*; @@ -847,4 +868,30 @@ mod tests { ); } } + + #[test] + #[cfg(feature = "full_tests")] + fn test_sin_pi_f64() { + for bits in (0..=u32::MAX).step_by(1 << 7) { + check_ulp( + f32::from_bits(bits) as f64, + sin_cos_pi_check_ulp_callback, + |x| sin_pi_f64(Scalar, Value(x)).0, + |x| reference_sin_cos_pi_f64(x).0, + ); + } + } + + #[test] + #[cfg(feature = "full_tests")] + fn test_cos_pi_f64() { + for bits in (0..=u32::MAX).step_by(1 << 7) { + check_ulp( + f32::from_bits(bits) as f64, + sin_cos_pi_check_ulp_callback, + |x| cos_pi_f64(Scalar, Value(x)).0, + |x| reference_sin_cos_pi_f64(x).1, + ) + } + } } -- 2.30.2