mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
uucore: format: extendedbigdecimal: Implement Neg trait
This is useful and will simplify some of the parsing logic later.
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt::Display;
|
||||
use std::ops::Add;
|
||||
use std::ops::Neg;
|
||||
|
||||
use bigdecimal::BigDecimal;
|
||||
use num_traits::FromPrimitive;
|
||||
@@ -227,6 +228,27 @@ impl PartialOrd for ExtendedBigDecimal {
|
||||
}
|
||||
}
|
||||
|
||||
impl Neg for ExtendedBigDecimal {
|
||||
type Output = Self;
|
||||
|
||||
fn neg(self) -> Self::Output {
|
||||
match self {
|
||||
Self::BigDecimal(bd) => {
|
||||
if bd.is_zero() {
|
||||
Self::MinusZero
|
||||
} else {
|
||||
Self::BigDecimal(bd.neg())
|
||||
}
|
||||
}
|
||||
Self::MinusZero => Self::BigDecimal(BigDecimal::zero()),
|
||||
Self::Infinity => Self::MinusInfinity,
|
||||
Self::MinusInfinity => Self::Infinity,
|
||||
Self::Nan => Self::MinusNan,
|
||||
Self::MinusNan => Self::Nan,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user