mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
uucore: format: extendedbigdecimal: Implement Neg trait
This is useful and will simplify some of the parsing logic later.
This commit is contained in:
parent
ace92dcca1
commit
5c06dd580b
1 changed files with 22 additions and 0 deletions
|
@ -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 {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue