blob: c8d2194f5163c4432b0a868637c52ddead62815e (
plain) (
tree)
|
|
pub struct MathDevice {
pub operand_1: u16,
pub operand_2: u16,
pub product_high: u16,
pub product_low: u16,
pub quotient: u16,
pub remainder: u16,
}
impl MathDevice {
pub fn new() -> Self {
Self {
operand_1: 0x0000,
operand_2: 0x0000,
product_high: 0x0000,
product_low: 0x0000,
quotient: 0x0000,
remainder: 0x0000,
}
}
pub fn multiply(&mut self) {
let (low, high) = self.operand_1.widening_mul(self.operand_2);
self.product_high = high;
self.product_low = low;
}
pub fn divide(&mut self) {
self.quotient = self.operand_1.checked_div(self.operand_2).unwrap_or(0);
}
pub fn modulo(&mut self) {
self.remainder = self.operand_1.checked_rem(self.operand_2).unwrap_or(0);
}
}
|