Merge pull request rust-lang/libm#209 from gnzlbg/fma
Fix overflow bugs in fma
This commit is contained in:
commit
b05e339db2
1 changed files with 21 additions and 2 deletions
|
|
@ -123,8 +123,8 @@ pub fn fma(x: f64, y: f64, z: f64) -> f64 {
|
|||
} else {
|
||||
/* r -= z */
|
||||
let t = rlo;
|
||||
rlo -= zlo;
|
||||
rhi = rhi - zhi - (t < rlo) as u64;
|
||||
rlo = rlo.wrapping_sub(zlo);
|
||||
rhi = rhi.wrapping_sub(zhi.wrapping_sub((t < rlo) as u64));
|
||||
if (rhi >> 63) != 0 {
|
||||
rlo = (-(rlo as i64)) as u64;
|
||||
rhi = (-(rhi as i64)) as u64 - (rlo != 0) as u64;
|
||||
|
|
@ -202,3 +202,22 @@ pub fn fma(x: f64, y: f64, z: f64) -> f64 {
|
|||
}
|
||||
scalbn(r, e)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn fma_segfault() {
|
||||
// These two inputs cause fma to segfault on release due to overflow:
|
||||
assert_eq!(
|
||||
fma(
|
||||
-0.0000000000000002220446049250313,
|
||||
-0.0000000000000002220446049250313,
|
||||
-0.0000000000000002220446049250313
|
||||
),
|
||||
-0.00000000000000022204460492503126,
|
||||
);
|
||||
|
||||
assert_eq!(fma(-0.992, -0.992, -0.992), -0.00793599999988632,);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue