make 16 bit precision work

This commit is contained in:
Corwin 2023-10-09 19:16:24 +01:00
parent 71e680f365
commit 09331d1cb5
No known key found for this signature in database

View file

@ -133,7 +133,7 @@ macro_rules! upcast_multiply_impl {
.wrapping_mul(b_frac)
.wrapping_add(b_floor.wrapping_mul(a_frac)),
)
.wrapping_add(a_frac.wrapping_mul(b_frac) >> n)
.wrapping_add(((a_frac as u32).wrapping_mul(b_frac as u32) >> n) as $T)
}
};
($T: ty, $Upcast: ty) => {
@ -1236,6 +1236,17 @@ mod tests {
);
}
#[test]
fn check_16_bit_precision_i32() {
let a: Num<i32, 16> = num!(1.923);
let b = num!(2.723);
assert_eq!(
a * b,
Num::from_raw(((a.to_raw() as i64 * b.to_raw() as i64) >> 16) as i32)
)
}
#[test]
fn test_numbers() {
// test addition