Skip to content

Commit

Permalink
drop rounding bias from 32-bit muls
Browse files Browse the repository at this point in the history
  • Loading branch information
jordens committed Jul 22, 2023
1 parent 2dd513c commit e244de8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,17 @@ impl MulScaled<Complex<i32>> for Complex<i32> {
let c = other.re as i64;
let d = other.im as i64;
Complex {
re: ((a * c - b * d + (1 << 30)) >> 31) as i32,
im: ((b * c + a * d + (1 << 30)) >> 31) as i32,
re: ((a * c - b * d) >> 31) as i32,
im: ((b * c + a * d) >> 31) as i32,
}
}
}

impl MulScaled<i32> for Complex<i32> {
fn mul_scaled(self, other: i32) -> Self {
Complex {
re: ((other as i64 * self.re as i64 + (1 << 30)) >> 31) as i32,
im: ((other as i64 * self.im as i64 + (1 << 30)) >> 31) as i32,
re: ((other as i64 * self.re as i64) >> 31) as i32,
im: ((other as i64 * self.im as i64) >> 31) as i32,
}
}
}
Expand Down

0 comments on commit e244de8

Please sign in to comment.