summaryrefslogtreecommitdiffstats
path: root/vendor/libm/src/math/sincosf.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/libm/src/math/sincosf.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/libm/src/math/sincosf.rs')
-rw-r--r--vendor/libm/src/math/sincosf.rs82
1 files changed, 72 insertions, 10 deletions
diff --git a/vendor/libm/src/math/sincosf.rs b/vendor/libm/src/math/sincosf.rs
index bb9a00392..9a4c36104 100644
--- a/vendor/libm/src/math/sincosf.rs
+++ b/vendor/libm/src/math/sincosf.rs
@@ -23,6 +23,7 @@ const S2PIO2: f32 = 2.0 * PI_2; /* 0x400921FB, 0x54442D18 */
const S3PIO2: f32 = 3.0 * PI_2; /* 0x4012D97C, 0x7F3321D2 */
const S4PIO2: f32 = 4.0 * PI_2; /* 0x401921FB, 0x54442D18 */
+#[cfg_attr(all(test, assert_no_panic), no_panic::no_panic)]
pub fn sincosf(x: f32) -> (f32, f32) {
let s: f32;
let c: f32;
@@ -65,11 +66,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);
}
}
@@ -89,11 +90,11 @@ pub fn sincosf(x: f32) -> (f32, f32) {
}
} else {
if sign {
- s = k_cosf((x + S4PIO2) as f64);
- c = k_sinf((x + S4PIO2) as f64);
+ s = k_sinf((x + S4PIO2) as f64);
+ c = k_cosf((x + S4PIO2) as f64);
} else {
- s = k_cosf((x - S4PIO2) as f64);
- c = k_sinf((x - S4PIO2) as f64);
+ s = k_sinf((x - S4PIO2) as f64);
+ c = k_cosf((x - S4PIO2) as f64);
}
}
@@ -115,9 +116,70 @@ pub fn sincosf(x: f32) -> (f32, f32) {
1 => (c, -s),
2 => (-s, -c),
3 => (-c, s),
- #[cfg(feature = "checked")]
+ #[cfg(debug_assertions)]
_ => unreachable!(),
- #[cfg(not(feature = "checked"))]
+ #[cfg(not(debug_assertions))]
_ => (0.0, 1.0),
}
}
+
+// PowerPC tests are failing on LLVM 13: https://github.com/rust-lang/rust/issues/88520
+#[cfg(not(target_arch = "powerpc64"))]
+#[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();
+ }
+
+ #[test]
+ fn rotational_symmetry() {
+ use core::f32::consts::PI;
+ const N: usize = 24;
+ for n in 0..N {
+ let theta = 2. * PI * (n as f32) / (N as f32);
+ let (s, c) = sincosf(theta);
+ let (s_plus, c_plus) = sincosf(theta + 2. * PI);
+ let (s_minus, c_minus) = sincosf(theta - 2. * PI);
+
+ const TOLERANCE: f32 = 1e-6;
+ assert!(
+ (s - s_plus).abs() < TOLERANCE,
+ "|{} - {}| = {} >= {}",
+ s,
+ s_plus,
+ (s - s_plus).abs(),
+ TOLERANCE
+ );
+ assert!(
+ (s - s_minus).abs() < TOLERANCE,
+ "|{} - {}| = {} >= {}",
+ s,
+ s_minus,
+ (s - s_minus).abs(),
+ TOLERANCE
+ );
+ assert!(
+ (c - c_plus).abs() < TOLERANCE,
+ "|{} - {}| = {} >= {}",
+ c,
+ c_plus,
+ (c - c_plus).abs(),
+ TOLERANCE
+ );
+ assert!(
+ (c - c_minus).abs() < TOLERANCE,
+ "|{} - {}| = {} >= {}",
+ c,
+ c_minus,
+ (c - c_minus).abs(),
+ TOLERANCE
+ );
+ }
+ }
+}