Support negation for signed numbers.

This commit is contained in:
2018-04-04 18:12:30 -04:00
parent 8a4693d30d
commit ae6a33f4b8

View File

@@ -88,6 +88,30 @@ impl Ord for SCN {
// //
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
impl Neg for SCN {
type Output = SCN;
fn neg(self) -> SCN {
if self.is_zero() {
self
} else {
SCN{ negative: !self.negative, value: self.value }
}
}
}
impl<'a> Neg for &'a SCN {
type Output = SCN;
fn neg(self) -> SCN {
if self.is_zero() {
self.clone()
} else {
SCN{ negative: !self.negative, value: self.value.clone() }
}
}
}
impl<'a> AddAssign<&'a SCN> for SCN { impl<'a> AddAssign<&'a SCN> for SCN {
fn add_assign(&mut self, rhs: &SCN) { fn add_assign(&mut self, rhs: &SCN) {
if self.negative == rhs.negative { if self.negative == rhs.negative {