-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/mul div #54
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
Merged
Merged
Feat/mul div #54
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d3f6d47
added mul_div functions with tests
aritkulova e430a20
added zero checks for div_128 and div_256 to be consistent with jet's…
aritkulova 0d5f5eb
added tests for new helper functions
aritkulova 2afb50f
typo in a test name
aritkulova e92bc6e
utilized convert and split functions
aritkulova 919565d
added mul_div docs;
aritkulova 8a84fd9
linting
aritkulova ea07ea8
added docs for new functions
aritkulova 989b27c
fixed typo
aritkulova 1a2f659
fixed bug in normalize_to_threshold funcs
aritkulova 6a8a86b
added more tests to cover new u512 division functionality
aritkulova 06a982f
bumped simplex version
aritkulova 36c5d71
optimization for calculate_normalizer_base_128
aritkulova efb2784
typo fixes
aritkulova 12c948a
a couple of new tests for calculate_normalizer_base_128
aritkulova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Hrom131 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| use crate::lib::u128::math::mul_128; | ||
| use crate::lib::u128::convert::u128_to_u256; | ||
|
|
||
| use crate::lib::u256::math::div_256; | ||
| use crate::lib::u256::convert::safe_u256_to_u128; | ||
|
|
||
| /// Calculates `floor(a * b / denominator)` with full precision. | ||
| /// Panics if the result overflows a u128 | ||
| pub fn mul_div_128(a: u128, b: u128, denominator: u128) -> u128 { | ||
| let denominator_256: u256 = u128_to_u256(denominator); | ||
|
|
||
| let result_256: u256 = div_256(mul_128(a, b), denominator_256); | ||
|
|
||
| safe_u256_to_u128(result_256) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| use crate::lib::u16::convert::u16_to_u32; | ||
| use crate::lib::u32::convert::safe_u32_to_u16; | ||
|
|
||
| /// Calculates `floor(a * b / denominator)` with full precision. | ||
| /// Panics if the result overflows a u16 | ||
| pub fn mul_div_16(a: u16, b: u16, denominator: u16) -> u16 { | ||
| let denominator_32: u32 = u16_to_u32(denominator); | ||
|
|
||
| let result_32: u32 = jet::divide_32(jet::multiply_16(a, b), denominator_32); | ||
|
|
||
| safe_u32_to_u16(result_32) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.