From 308c44f61660f2b0ef92bad4d96bf4d1029dd458 Mon Sep 17 00:00:00 2001 From: Peter Michael Green Date: Tue, 27 Dec 2022 08:44:15 +0000 Subject: [PATCH] num-rational - work around floating point issue on armel. --- src/num-rational/debian/changelog | 9 +++ .../debian/patches/fix-test-ldexp-armel.patch | 64 +++++++++++++++++++ src/num-rational/debian/patches/series | 1 + 3 files changed, 74 insertions(+) create mode 100644 src/num-rational/debian/patches/fix-test-ldexp-armel.patch create mode 100644 src/num-rational/debian/patches/series diff --git a/src/num-rational/debian/changelog b/src/num-rational/debian/changelog index 530a351c2..418681f7e 100644 --- a/src/num-rational/debian/changelog +++ b/src/num-rational/debian/changelog @@ -1,3 +1,12 @@ +rust-num-rational (0.4.1-2) UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; urgency=medium + + * Team upload. + * Package num-rational 0.4.1 from crates.io using debcargo 2.6.0 + * Work around testsuite failure caused by floating point arithmetic + issue on armel (Closes: #1027011). + + -- Peter Michael Green Tue, 27 Dec 2022 08:42:33 +0000 + rust-num-rational (0.4.1-1) unstable; urgency=medium * Team upload. diff --git a/src/num-rational/debian/patches/fix-test-ldexp-armel.patch b/src/num-rational/debian/patches/fix-test-ldexp-armel.patch new file mode 100644 index 000000000..12ef4cc07 --- /dev/null +++ b/src/num-rational/debian/patches/fix-test-ldexp-armel.patch @@ -0,0 +1,64 @@ +Workaround floating point issue in tests on armel + +Specifically powi seems to have issues with extreme values on armel, as does +floating point division underflowing to zero before it really should. The +implementation used here, however appears to work correctly. + +See https://github.com/rust-num/num-rational/issues/111 + +Index: rust-num-rational-0.4.1/src/lib.rs +=================================================================== +--- rust-num-rational-0.4.1.orig/src/lib.rs ++++ rust-num-rational-0.4.1/src/lib.rs +@@ -3068,6 +3068,24 @@ mod test { + assert_eq!(Ratio::::new_raw(0, 0).to_f64(), None); + } + ++ // powi in the standard library seems to have problems with very ++ // small values on arm softfloat, use our own implementation instead. ++ fn naive_powi(mut a : f64, b : i32) -> f64 { ++ ++ let mut res = 1.0; ++ let negative = b < 0; ++ ++ let b = b.abs(); ++ for i in 0..b { ++ res *= a; ++ } ++ if negative { ++ res = 2.0/res; ++ res = res * 0.5; ++ } ++ return res; ++ } ++ + #[test] + fn test_ldexp() { + use core::f64::{INFINITY, MAX_EXP, MIN_EXP, NAN, NEG_INFINITY}; +@@ -3078,19 +3096,19 @@ mod test { + + // Cases where ldexp is equivalent to multiplying by 2^exp because there's no over- or + // underflow. +- assert_eq!(ldexp(3.5, 5), 3.5 * 2f64.powi(5)); +- assert_eq!(ldexp(1.0, MAX_EXP - 1), 2f64.powi(MAX_EXP - 1)); +- assert_eq!(ldexp(2.77, MIN_EXP + 3), 2.77 * 2f64.powi(MIN_EXP + 3)); ++ assert_eq!(ldexp(3.5, 5), 3.5 * naive_powi(2.0,5)); ++ assert_eq!(ldexp(1.0, MAX_EXP - 1), naive_powi(2.0,MAX_EXP - 1)); ++ assert_eq!(ldexp(2.77, MIN_EXP + 3), 2.77 * naive_powi(2.0,MIN_EXP + 3)); + + // Case where initial value is subnormal +- assert_eq!(ldexp(5e-324, 4), 5e-324 * 2f64.powi(4)); +- assert_eq!(ldexp(5e-324, 200), 5e-324 * 2f64.powi(200)); ++ assert_eq!(ldexp(5e-324, 4), 5e-324 * naive_powi(2.0,4)); ++ assert_eq!(ldexp(5e-324, 200), 5e-324 * naive_powi(2.0,200)); + + // Near underflow (2^exp is too small to represent, but not x*2^exp) +- assert_eq!(ldexp(4.0, MIN_EXP - 3), 2f64.powi(MIN_EXP - 1)); ++ assert_eq!(ldexp(4.0, MIN_EXP - 3), naive_powi(2.0,MIN_EXP - 1)); + + // Near overflow +- assert_eq!(ldexp(0.125, MAX_EXP + 3), 2f64.powi(MAX_EXP)); ++ assert_eq!(ldexp(0.125, MAX_EXP + 3), naive_powi(2.0,MAX_EXP)); + + // Overflow and underflow cases + assert_eq!(ldexp(1.0, MIN_EXP - 54), 0.0); diff --git a/src/num-rational/debian/patches/series b/src/num-rational/debian/patches/series new file mode 100644 index 000000000..374577cc2 --- /dev/null +++ b/src/num-rational/debian/patches/series @@ -0,0 +1 @@ +fix-test-ldexp-armel.patch -- 2.39.5