Merge pull request #179 from m1el/issue178_exp2_wrap
Fixed u32 overflow in exp2
This commit is contained in:
commit
98ae0dfd7e
@ -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));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user