Extend PerThing + Saturating (#5281)

* Extend PerThing + Saturating

* Add saturating_pow to Saturating
* Add saturating_truncating_mul to PerThing (rounding-down mul)
* Add saturating_reciprocal_mul to PerThing (divide x by perthing)
* Provide default methods where possible

* Restore const functions

* Fix test

* Update primitives/arithmetic/src/per_things.rs

Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Add comment and test verifying no overflow

* Formatting

* Fix possible overflow and change type constraint

* Use overflow pruning for all mul

* Formatting and comments

* Improve comments and names

* Comments in `rational_mul_correction` explain overflow aversion.

* Test rational_mul_correction

* Formatting

* Docs and formatting

* Add new trait methods to Perthing type impl

* Fix signature

* saturating_pow for Delegations

* Add missing trait method to impl

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
This commit is contained in:
Joseph Mark
2020-03-29 13:24:11 +02:00
committed by GitHub
parent d7ffef43ce
commit e8835d64a1
4 changed files with 536 additions and 151 deletions
+7
View File
@@ -62,6 +62,13 @@ impl<Balance: Saturating> Saturating for Delegations<Balance> {
capital: self.capital.saturating_mul(o.capital),
}
}
fn saturating_pow(self, exp: usize) -> Self {
Self {
votes: self.votes.saturating_pow(exp),
capital: self.capital.saturating_pow(exp),
}
}
}
impl<