Skip to content

Commit

Permalink
allow force_eval! to produce a result and use that result to more exp…
Browse files Browse the repository at this point in the history
…licitly force rounding on x87.
  • Loading branch information
Peter Michael Green committed Jan 4, 2022
1 parent c54ade6 commit 92da66a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/math/fma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ 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);
let result = force_eval!(result);
assert_eq!(result, -0.007936000000000007,);
}

Expand Down
2 changes: 1 addition & 1 deletion src/math/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
macro_rules! force_eval {
($e:expr) => {
unsafe {
::core::ptr::read_volatile(&$e);
::core::ptr::read_volatile(&$e)
}
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/math/pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ mod tests {
let res = computed(*val);

#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
force_eval!(exp);
let exp = force_eval!(exp);
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
force_eval!(res);
let res = force_eval!(res);
assert!(
if exp.is_nan() {
res.is_nan()
Expand Down
10 changes: 5 additions & 5 deletions src/math/rem_pio2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub(crate) fn rem_pio2(x: f64) -> (i32, f64, f64) {
// 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);
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;
Expand Down Expand Up @@ -196,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)
Expand Down
2 changes: 1 addition & 1 deletion src/math/rem_pio2f.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub(crate) fn rem_pio2f(x: f32) -> (i32, f64) {
// 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);
let tmp = force_eval!(tmp);
let f_n = tmp - TOINT;
return (f_n as i32, x64 - f_n * PIO2_1 - f_n * PIO2_1T);
}
Expand Down
2 changes: 1 addition & 1 deletion src/math/sin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ fn test_near_pi() {
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);
let result = force_eval!(result);
assert_eq!(result, sx);
}

0 comments on commit 92da66a

Please sign in to comment.