This repository was archived by the owner on Apr 28, 2025. It is now read-only.
This repository was archived by the owner on Apr 28, 2025. It is now read-only.
sincosf returns wrong results on interval (7*pi/4, 9*pi/4) #232
Closed
Description
Using libm
0.2.0 / master a5e39d8f1ad2ad669e62565f98f1dc86ea5fed96
, this simple test case exercising 2*pi
symmetry:
#[cfg(test)]
mod tests {
use libm::sincosf;
fn d2r(d: f32) -> f32 {
use std::f32::consts::PI;
d * PI / 180.
}
#[test]
fn test_sincosf() {
assert_eq!(sincosf(d2r(330.)), sincosf(d2r(330. - 360.)));
}
}
Fails (for non-limited-precision reasons), with the message:
---- tests::test_sincosf stdout ----
thread 'tests::test_sincosf' panicked at 'assertion failed: `(left == right)`
left: `(0.86602545, -0.4999999)`,
right: `(-0.5, 0.8660254)`', src/lib.rs:12:9
Precision issues aside, note that the sin/cos components are reversed.
Some quick binary searching shows that this condition persists across the interval of [316, 404] degrees, which is to say it appears to affect (7pi/4, 9pi/4) rad.
Metadata
Metadata
Assignees
Labels
No labels