From 3b3f3e977cdbdf57a70fb3565dc59806df75f81b Mon Sep 17 00:00:00 2001 From: Christopher Serr Date: Fri, 18 Oct 2019 15:23:57 +0200 Subject: [PATCH] Fix sincosf(PI) (#229) Looks like the implementation was not ported correctly. Some negations were forgotten in a certain branch. Here is the original code in musl that has the negations: https://github.com/bpowers/musl/blob/94cb2ec2a0ffcb47d24dbf7a30e462505396cf54/src/math/sincosf.c#L66-L67 Resolves rust-lang/libm#228 --- .../libm/src/math/sincosf.rs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/library/compiler-builtins/libm/src/math/sincosf.rs b/library/compiler-builtins/libm/src/math/sincosf.rs index d4e0772d5b10..df644f3b5e3c 100644 --- a/library/compiler-builtins/libm/src/math/sincosf.rs +++ b/library/compiler-builtins/libm/src/math/sincosf.rs @@ -65,11 +65,11 @@ pub fn sincosf(x: f32) -> (f32, f32) { /* -sin(x+c) is not correct if x+c could be 0: -0 vs +0 */ else { if sign { - s = k_sinf((x + S2PIO2) as f64); - c = k_cosf((x + S2PIO2) as f64); + s = -k_sinf((x + S2PIO2) as f64); + c = -k_cosf((x + S2PIO2) as f64); } else { - s = k_sinf((x - S2PIO2) as f64); - c = k_cosf((x - S2PIO2) as f64); + s = -k_sinf((x - S2PIO2) as f64); + c = -k_cosf((x - S2PIO2) as f64); } } @@ -121,3 +121,16 @@ pub fn sincosf(x: f32) -> (f32, f32) { _ => (0.0, 1.0), } } + +#[cfg(test)] +mod tests { + use super::sincosf; + use crate::_eqf; + + #[test] + fn with_pi() { + let (s, c) = sincosf(core::f32::consts::PI); + _eqf(s.abs(), 0.0).unwrap(); + _eqf(c, -1.0).unwrap(); + } +}