-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Use sensible maths for from_rational
#13660
Conversation
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Division by zero should panic if there is no way to return an It's reasonable to introduce alternative versions of these functions which return |
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
This reverts commit 7e88ac7.
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Yea the case that it wont show up in tests anymore is indeed bad. So having |
Yes, think so. |
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
% the comment on multiply_rational
.
Still need to figure out how to run these tests in the CI.
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
Signed-off-by: Oliver Tale-Yazdi <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the logic looks good to me, however we should probably fix the staking test to actually reflect this properly and not via magic numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approving this as fixing the staking test properly could be done as part of another issue
bot merge |
This reverts #13651 since we merged the proper fix in #13660 Signed-off-by: Oliver Tale-Yazdi <[email protected]>
* Use sensible maths for from_rational * Fixes * Fixes * More fixes * Remove debugging * Add fuzzer tests Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Prevent panics Signed-off-by: Oliver Tale-Yazdi <[email protected]> * docs Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Clean up old code Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Test all rounding modes of from_rational Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Clean up code Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Revert "Prevent panics" This reverts commit 7e88ac7. * fix imports Signed-off-by: Oliver Tale-Yazdi <[email protected]> * cleanup Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Fuzz test multiply_rational Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Fix import Signed-off-by: Oliver Tale-Yazdi <[email protected]> * fmt Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Return None in multiply_rational on zero div Signed-off-by: Oliver Tale-Yazdi <[email protected]> --------- Signed-off-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Oliver Tale-Yazdi <[email protected]>
* Use sensible maths for from_rational * Fixes * Fixes * More fixes * Remove debugging * Add fuzzer tests Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Prevent panics Signed-off-by: Oliver Tale-Yazdi <[email protected]> * docs Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Clean up old code Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Test all rounding modes of from_rational Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Clean up code Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Revert "Prevent panics" This reverts commit 7e88ac7. * fix imports Signed-off-by: Oliver Tale-Yazdi <[email protected]> * cleanup Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Fuzz test multiply_rational Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Fix import Signed-off-by: Oliver Tale-Yazdi <[email protected]> * fmt Signed-off-by: Oliver Tale-Yazdi <[email protected]> * Return None in multiply_rational on zero div Signed-off-by: Oliver Tale-Yazdi <[email protected]> --------- Signed-off-by: Oliver Tale-Yazdi <[email protected]> Co-authored-by: Oliver Tale-Yazdi <[email protected]>
Old maths had all sorts of small edge cases with rounding which broke expectations. Now we just use the stuff which is already proven.
Note one test in staking was relying on the old buggy maths. It had to be corrected with some dirty magic numbers. Not sure if @kianenigma wants to take a look. A test was added in
per_things
(from_rational_with_rounding_breakage_2
) to demonstrate that the old numbers for which this tests behaviour relied on are in fact wrong and do definitely break expectations.Possibly fix for paritytech/polkadot-sdk#200