Skip to content

Commit

Permalink
Merge pull request #269 from ajtribick/fma_wrapping_neg
Browse files Browse the repository at this point in the history
  • Loading branch information
Amanieu authored Oct 1, 2022
2 parents 14a76ea + f0cc791 commit 593764b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/math/fma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ pub fn fma(x: f64, y: f64, z: f64) -> f64 {
rlo = res;
rhi = rhi.wrapping_sub(zhi.wrapping_add(borrow as u64));
if (rhi >> 63) != 0 {
rlo = (-(rlo as i64)) as u64;
rhi = (-(rhi as i64)) as u64 - (rlo != 0) as u64;
rlo = (rlo as i64).wrapping_neg() as u64;
rhi = (rhi as i64).wrapping_neg() as u64 - (rlo != 0) as u64;
sign = (sign == 0) as i32;
}
nonzero = (rhi != 0) as i32;
Expand Down Expand Up @@ -232,4 +232,12 @@ mod tests {
-3991680619069439e277
);
}

#[test]
fn fma_underflow() {
assert_eq!(
fma(1.1102230246251565e-16, -9.812526705433188e-305, 1.0894e-320),
0.0,
);
}
}

0 comments on commit 593764b

Please sign in to comment.