diff --git a/library/compiler-builtins/libm/src/math/exp2.rs b/library/compiler-builtins/libm/src/math/exp2.rs index 570ca315b094..c2192fde5a08 100644 --- a/library/compiler-builtins/libm/src/math/exp2.rs +++ b/library/compiler-builtins/libm/src/math/exp2.rs @@ -373,7 +373,7 @@ pub fn exp2(mut x: f64) -> f64 { /* Reduce x, computing z, i0, and k. */ let ui = f64::to_bits(x + redux); let mut i0 = ui as u32; - i0 += TBLSIZE as u32 / 2; + i0 = i0.wrapping_add(TBLSIZE as u32 / 2); let ku = i0 / TBLSIZE as u32 * TBLSIZE as u32; let ki = ku as i32 / TBLSIZE as i32; i0 %= TBLSIZE as u32; @@ -387,3 +387,9 @@ pub fn exp2(mut x: f64) -> f64 { scalbn(r, ki) } + +#[test] +fn i0_wrap_test() { + let x = -3.0 / 256.0; + assert_eq!(exp2(x), f64::from_bits(0x3fefbdba3692d514)); +}