Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce checked_div for PerThings and checked_rational_mul_correction #1936

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Gioyik
Copy link

@Gioyik Gioyik commented Oct 18, 2023

Fixes #199
Follow up from paritytech/substrate#14673

Introduces checked_div and checked_rational_mul_correction

@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: test-linux-stable 3/3
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/4011655

@Gioyik Gioyik marked this pull request as ready for review October 19, 2023 09:54
@Gioyik Gioyik requested a review from a team October 19, 2023 09:54
@ggwpez ggwpez self-requested a review October 19, 2023 09:58
substrate/primitives/arithmetic/src/per_things.rs Outdated Show resolved Hide resolved
if P::Inner::is_zero(&denom) {
return Err("Division by zero")
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 529 maybe there is a checked_rem? Then we dont need this if.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what you mean by checked_rem

substrate/primitives/arithmetic/src/per_things.rs Outdated Show resolved Hide resolved
@Gioyik Gioyik requested a review from ggwpez October 24, 2023 16:53
pub const fn multiply_by_rational_with_rounding(
a: u128,
b: u128,
c: u128,
r: Rounding,
) -> Option<u128> {
match checked_multiply_by_rational_with_rounding(a, b, c, r) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
match checked_multiply_by_rational_with_rounding(a, b, c, r) {
checked_multiply_by_rational_with_rounding(a, b, c, r).ok()

impl CheckedDiv for $name {
#[inline]
fn checked_div(&self, rhs: &Self) -> Option<Self> {
if rhs.0.is_zero() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use from_rational_with_rounding

@bkchr
Copy link
Member

bkchr commented Jul 24, 2024

bot fmt

@command-bot
Copy link

command-bot bot commented Jul 24, 2024

@bkchr https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6806184 was started for your command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh". Check out https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/pipelines?page=1&scope=all&username=group_605_bot to know what else is being executed currently.

Comment bot cancel 1-a33e4065-4995-40e1-b5b4-31540197cc24 to cancel this command or bot cancel to cancel all commands in this pull request.

Copy link

We are migrating the command bot to be a GitHub Action

Please, see the documentation on how to use it

@bkchr
Copy link
Member

bkchr commented Jul 24, 2024

@Gioyik can you take another look?

@command-bot
Copy link

command-bot bot commented Jul 24, 2024

@bkchr Command "$PIPELINE_SCRIPTS_DIR/commands/fmt/fmt.sh" has finished. Result: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6806184 has finished. If any artifacts were generated, you can download them from https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6806184/artifacts/download.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce checked PerThing arithmetics
4 participants