Skip to content

Commit

Permalink
Add references to ticket #920 in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed May 25, 2021
1 parent 121deaa commit 31de6c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/std/src/math/uint128.rs
Expand Up @@ -232,7 +232,7 @@ impl Uint128 {
if denominator == 0 {
panic!("Denominator must not be zero");
}
// TODO: minimize rounding that takes place (using gcd algorithm)
// TODO: avoid overflow in multiplication (https://github.com/CosmWasm/cosmwasm/issues/920)
let val = self.u128() * numerator / denominator;
Uint128::from(val)
}
Expand Down Expand Up @@ -414,6 +414,8 @@ mod tests {
assert_eq!(base.multiply_ratio(1u128, 1u128), Uint128(500));
assert_eq!(base.multiply_ratio(3u128, 3u128), Uint128(500));
assert_eq!(base.multiply_ratio(654321u128, 654321u128), Uint128(500));
// Reactivate after https://github.com/CosmWasm/cosmwasm/issues/920
// assert_eq!(base.multiply_ratio(u128::MAX, u128::MAX), Uint128(500));

// factor 3/2
assert_eq!(base.multiply_ratio(3u128, 2u128), Uint128(750));
Expand Down
4 changes: 3 additions & 1 deletion packages/std/src/math/uint64.rs
Expand Up @@ -221,7 +221,7 @@ impl Uint64 {
if denominator == 0 {
panic!("Denominator must not be zero");
}
// TODO: minimize rounding that takes place (using gcd algorithm)
// TODO: avoid overflow in multiplication (https://github.com/CosmWasm/cosmwasm/issues/920)
let val = self.u64() * numerator / denominator;
Uint64::from(val)
}
Expand Down Expand Up @@ -400,6 +400,8 @@ mod tests {
assert_eq!(base.multiply_ratio(1u64, 1u64), Uint64(500));
assert_eq!(base.multiply_ratio(3u64, 3u64), Uint64(500));
assert_eq!(base.multiply_ratio(654321u64, 654321u64), Uint64(500));
// Reactivate after https://github.com/CosmWasm/cosmwasm/issues/920
// assert_eq!(base.multiply_ratio(u64::MAX, u64::MAX), Uint64(500));

// factor 3/2
assert_eq!(base.multiply_ratio(3u64, 2u64), Uint64(750));
Expand Down

0 comments on commit 31de6c7

Please sign in to comment.