1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
This patch is based on the commit described below, which has
been submitted as part of https://github.com/rust-lang/libm/pull/249
adapted for use in the Debian package.
commit 9b6f469d5b3e35f793800da1c58070da2478f76e
Author: Peter Michael Green <plugwash@debian.org>
Date: Tue Jan 4 20:51:40 2022 +0000
allow force_eval! to produce a result and use that result to more explicitly force rounding on x87.
@@ -220,7 +220,8 @@ mod tests {
let result = fma(-0.992, -0.992, -0.992);
//force rounding to storage format on x87 to prevent superious errors.
- #[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]force_eval!(result);
+ #[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
+ let result = force_eval!(result);
assert_eq!(result, -0.00793599999988632,);
}
}
@@ -1,7 +1,7 @@
macro_rules! force_eval {
($e:expr) => {
unsafe {
- ::core::ptr::read_volatile(&$e);
+ ::core::ptr::read_volatile(&$e)
}
};
}
@@ -484,8 +484,10 @@ mod tests {
let exp = expected(*val);
let res = computed(*val);
- #[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]force_eval!(exp);
- #[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]force_eval!(res);
+ #[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
+ let exp = force_eval!(exp);
+ #[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
+ let res = force_eval!(res);
assert!(
if exp.is_nan() {
res.is_nan()
@@ -53,7 +53,8 @@ pub(crate) fn rem_pio2(x: f64) -> (i32,
let tmp = x as f64 * INV_PIO2 + TO_INT;
// force rounding of tmp to it's storage format on x87 to avoid
// excess precision issues.
- #[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]force_eval!(tmp);
+ #[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
+ let tmp = force_eval!(tmp);
let f_n = tmp - TO_INT;
let n = f_n as i32;
let mut r = x - f_n * PIO2_1;
@@ -195,25 +196,25 @@ mod tests {
#[test]
fn test_near_pi() {
let arg = 3.141592025756836;
- force_eval!(arg);
+ let arg = force_eval!(arg);
assert_eq!(
rem_pio2(arg),
(2, -6.278329573009626e-7, -2.1125998133974653e-23)
);
let arg = 3.141592033207416;
- force_eval!(arg);
+ let arg = force_eval!(arg);
assert_eq!(
rem_pio2(arg),
(2, -6.20382377148128e-7, -2.1125998133974653e-23)
);
let arg = 3.141592144966125;
- force_eval!(arg);
+ let arg = force_eval!(arg);
assert_eq!(
rem_pio2(arg),
(2, -5.086236681942706e-7, -2.1125998133974653e-23)
);
let arg = 3.141592979431152;
- force_eval!(arg);
+ let arg = force_eval!(arg);
assert_eq!(
rem_pio2(arg),
(2, 3.2584135866119817e-7, -2.1125998133974653e-23)
@@ -46,7 +46,8 @@ pub(crate) fn rem_pio2f(x: f32) -> (i32,
let tmp = x64 * INV_PIO2 + TOINT;
// force rounding of tmp to it's storage format on x87 to avoid
// excess precision issues.
- #[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]force_eval!(tmp);
+ #[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
+ let tmp = force_eval!(tmp);
let f_n = tmp - TOINT;
return (f_n as i32, x64 - f_n * PIO2_1 - f_n * PIO2_1T);
}
@@ -82,6 +82,7 @@ fn test_near_pi() {
let x = f64::from_bits(0x400921fb000FD5DD); // 3.141592026217707
let sx = f64::from_bits(0x3ea50d15ced1a4a2); // 6.273720864039205e-7
let result = sin(x);
- #[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]force_eval!(result);
+ #[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
+ let result = force_eval!(result);
assert_eq!(result, sx);
}
|