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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use super::*;

impl Zero for NyarDecimal {
    fn zero() -> Self {
        Self { sign: Sign::Plus, digits: ZERO.clone(), scale: 0 }
    }

    fn is_zero(&self) -> bool {
        todo!()
    }
}
impl One for NyarDecimal {
    fn one() -> Self {
        Self { sign: Sign::Plus, digits: ONE.clone(), scale: 0 }
    }
}

impl Neg for NyarDecimal {
    type Output = Self;

    fn neg(self) -> Self::Output {
        Self { sign: -self.sign, digits: self.digits, scale: self.scale }
    }
}

impl Add for NyarDecimal {
    type Output = Self;

    fn add(self, rhs: Self) -> Self::Output {
        self.delegate().add(rhs.delegate()).into()
    }
}
impl Sub for NyarDecimal {
    type Output = Self;

    fn sub(self, rhs: Self) -> Self::Output {
        self.delegate().sub(rhs.delegate()).into()
    }
}

impl Mul for NyarDecimal {
    type Output = Self;

    fn mul(self, rhs: Self) -> Self::Output {
        self.delegate().mul(rhs.delegate()).into()
    }
}

impl Div for NyarDecimal {
    type Output = Self;

    fn div(self, rhs: Self) -> Self::Output {
        self.delegate().div(rhs.delegate()).into()
    }
}

impl Rem for NyarDecimal {
    type Output = Self;

    fn rem(self, rhs: Self) -> Self::Output {
        self.delegate().rem(rhs.delegate()).into()
    }
}

impl Signed for NyarDecimal {
    fn abs(&self) -> Self {
        Self { sign: Sign::Plus, digits: self.digits.clone(), scale: self.scale }
    }

    fn abs_sub(&self, other: &Self) -> Self {
        self.delegate().abs_sub(&other.delegate()).into()
    }

    fn signum(&self) -> Self {
        self.delegate().signum().into()
    }

    fn is_positive(&self) -> bool {
        self.sign == Sign::Plus
    }

    fn is_negative(&self) -> bool {
        self.sign == Sign::Minus
    }
}