Enable fixed point u128 (#6214)

* Add fixed u128.

* remove move

* Change sat_from_integer impl.

* checked_pow is always positive

* Revert.

* rename fixed file

* Rename to FixedI

* rename fixed file

* Add newline.

* Use Multiplier in impls.

* Renames negate() to saturating_negate().

* Uncomment test.

* Add Signed to macro.

* Add some tests for Saturating trait.
This commit is contained in:
Marcio Diaz
2020-06-06 13:04:39 +02:00
committed by GitHub
parent 0761a8e0c3
commit 7c051caa42
11 changed files with 424 additions and 342 deletions
@@ -145,7 +145,15 @@ impl<T: Clone + Zero + One + PartialOrd + CheckedMul + Bounded + num_traits::Sat
}
fn saturating_pow(self, exp: usize) -> Self {
checked_pow(self, exp).unwrap_or_else(Bounded::max_value)
let neg = self < T::zero() && exp % 2 != 0;
checked_pow(self, exp)
.unwrap_or_else(||
if neg {
Bounded::min_value()
} else {
Bounded::max_value()
}
)
}
}