Skip to content

Commit

Permalink
Fix rint and rintf on x87.
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Michael Green committed Oct 5, 2023
1 parent 5bcbc3b commit 5594834
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/math/rint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ pub fn rint(x: f64) -> f64 {
x
} else {
let ans = if is_positive {
x + one_over_e - one_over_e
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
let x = force_eval!(x);
let xplusoneovere = x + one_over_e;
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
let xplusoneovere = force_eval!(xplusoneovere);
xplusoneovere - one_over_e
} else {
x - one_over_e + one_over_e
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
let x = force_eval!(x);
let xminusoneovere = x - one_over_e;
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
let xminusoneovere = force_eval!(xminusoneovere);
xminusoneovere + one_over_e
};

if ans == 0.0 {
Expand Down
14 changes: 12 additions & 2 deletions src/math/rintf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ pub fn rintf(x: f32) -> f32 {
x
} else {
let ans = if is_positive {
x + one_over_e - one_over_e
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
let x = force_eval!(x);
let xplusoneovere = x + one_over_e;
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
let xplusoneovere = force_eval!(xplusoneovere);
xplusoneovere - one_over_e
} else {
x - one_over_e + one_over_e
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
let x = force_eval!(x);
let xminusoneovere = x - one_over_e;
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
let xminusoneovere = force_eval!(xminusoneovere);
xminusoneovere + one_over_e
};

if ans == 0.0 {
Expand Down

0 comments on commit 5594834

Please sign in to comment.