blob: cefb572b040ffb3037c106bc51a3baa5c807944e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
pub struct MathDevice {
pub operand_1: u16,
pub operand_2: u16,
}
impl MathDevice {
pub fn new() -> Self {
Self {
operand_1: 0x0000,
operand_2: 0x0000,
}
}
pub fn multiply_high(&mut self) -> u16 {
let (_, high) = self.operand_1.widening_mul(self.operand_2);
return high;
}
pub fn multiply_low(&mut self) -> u16 {
let (low, _) = self.operand_1.widening_mul(self.operand_2);
return low;
}
pub fn divide(&mut self) -> u16 {
self.operand_1.checked_div(self.operand_2).unwrap_or(0)
}
pub fn modulo(&mut self) -> u16 {
self.operand_1.checked_rem(self.operand_2).unwrap_or(0)
}
}
|