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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use std::ops::Rem;

use crate::Bit;
use crate::Int;

use crate::int::div::divisor;

impl Rem for Int {

    type Output = Self;
    
    fn rem(self, other: Self) -> Self {
        
        if self == Int::zero() {
            Int::zero()
        }
        
        else if other == Int::zero() {
            panic!("a/0 is undefined!")
        }
        
        else {
    
            let (_, r) = divisor(self.magnitude, other.magnitude);
    
            if self.sign && r != vec![Bit::Zero] {
                Int { magnitude: r, sign: true }
            } else {
                Int { magnitude: r, sign: false }
            }
    
        }
    }

}

impl Rem for &Int {

    type Output = Int;
    
    fn rem(self, b: Self) -> Int {
        self.clone() % b.clone()
    }

}