Skip to content

Commit

Permalink
primitive-types: add U128 full_mul (#546)
Browse files Browse the repository at this point in the history
* primitive-types: add U128 full_mul

* primitive-types: update the changelog

* Apply suggestions from code review

Co-authored-by: David <dvdplm@gmail.com>

Co-authored-by: David <dvdplm@gmail.com>
  • Loading branch information
ordian and dvdplm committed May 24, 2021
1 parent 0867e48 commit 0ac86ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions primitive-types/CHANGELOG.md
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog].
[Keep a Changelog]: http://keepachangelog.com/en/1.0.0/

## [Unreleased]
- Added `U128::full_mul` method. [#546](https://github.com/paritytech/parity-common/pull/546)
### Breaking
- Updated `scale-info` to 0.6. [#519](https://github.com/paritytech/parity-common/pull/519)

## [0.9.0] - 2021-01-27
### Breaking
Expand Down
13 changes: 11 additions & 2 deletions primitive-types/src/lib.rs
Expand Up @@ -125,9 +125,18 @@ mod rlp {

impl_fixed_hash_conversions!(H256, H160);

impl U128 {
/// Multiplies two 128-bit integers to produce full 256-bit integer.
/// Overflow is not possible.
#[inline(always)]
pub fn full_mul(self, other: U128) -> U256 {
U256(uint_full_mul_reg!(U128, 2, self, other))
}
}

impl U256 {
/// Multiplies two 256-bit integers to produce full 512-bit integer
/// No overflow possible
/// Multiplies two 256-bit integers to produce full 512-bit integer.
/// Overflow is not possible.
#[inline(always)]
pub fn full_mul(self, other: U256) -> U512 {
U512(uint_full_mul_reg!(U256, 4, self, other))
Expand Down

0 comments on commit 0ac86ef

Please sign in to comment.