Skip to content

Commit ef9feeb

Browse files
CryZealexcrichton
authored andcommitted
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
1 parent d47cfe6 commit ef9feeb

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

libm/src/math/sincosf.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ pub fn sincosf(x: f32) -> (f32, f32) {
6565
/* -sin(x+c) is not correct if x+c could be 0: -0 vs +0 */
6666
else {
6767
if sign {
68-
s = k_sinf((x + S2PIO2) as f64);
69-
c = k_cosf((x + S2PIO2) as f64);
68+
s = -k_sinf((x + S2PIO2) as f64);
69+
c = -k_cosf((x + S2PIO2) as f64);
7070
} else {
71-
s = k_sinf((x - S2PIO2) as f64);
72-
c = k_cosf((x - S2PIO2) as f64);
71+
s = -k_sinf((x - S2PIO2) as f64);
72+
c = -k_cosf((x - S2PIO2) as f64);
7373
}
7474
}
7575

@@ -121,3 +121,16 @@ pub fn sincosf(x: f32) -> (f32, f32) {
121121
_ => (0.0, 1.0),
122122
}
123123
}
124+
125+
#[cfg(test)]
126+
mod tests {
127+
use super::sincosf;
128+
use crate::_eqf;
129+
130+
#[test]
131+
fn with_pi() {
132+
let (s, c) = sincosf(core::f32::consts::PI);
133+
_eqf(s.abs(), 0.0).unwrap();
134+
_eqf(c, -1.0).unwrap();
135+
}
136+
}

0 commit comments

Comments
 (0)