-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Performance] Don't go into main loop if it is last period for vesting and unlock #141
Changes from 11 commits
c47affe
786b6dd
de0b413
f0b7605
88bb981
3f70c52
9759972
f0b799d
602da5f
b25141a
2f628d0
366ad87
61a5ad0
eabd31b
ab81fbd
483248b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,6 +56,19 @@ module aptos_std::fixed_point64 { | |
ensures result.value == x.value + y.value; | ||
} | ||
|
||
/// Returns x / y. The result cannot be greater than MAX_U128. | ||
public fun divide(x: FixedPoint64, y: FixedPoint64): FixedPoint64 { | ||
let x_raw = get_raw_value(x); | ||
let y_raw = get_raw_value(y); | ||
// If it is divisable, return the result. If not, return the result + 1. | ||
let result = (x_raw as u256) / (y_raw as u256); | ||
if ((x_raw as u256) % (y_raw as u256) != 0) { | ||
result = result + 1; | ||
}; | ||
assert!(result <= MAX_U128, ERATIO_OUT_OF_RANGE); | ||
create_from_raw_value((result as u128)) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this division is correct. If both numbers have 64 bit allotted for fractional value, after division, the fraction would disappear. I believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we don't even need it right now as we did not use this anymore. Do we need to keep this function? |
||
|
||
/// Multiply a u128 integer by a fixed-point number, truncating any | ||
/// fractional part of the product. This will abort if the product | ||
/// overflows. | ||
|
@@ -85,6 +98,17 @@ module aptos_std::fixed_point64 { | |
(val * multiplier.value) >> 64 | ||
} | ||
|
||
public fun multiply_u128_return_fixpoint64(val: u128, multiplier: FixedPoint64): FixedPoint64 { | ||
// The product of two 128 bit values has 256 bits, so perform the | ||
// multiplication with u256 types and keep the full 256 bit product | ||
// to avoid losing accuracy. | ||
let unscaled_product = (val as u256) * (multiplier.value as u256); | ||
// Check whether the value is too large. | ||
assert!(unscaled_product <= MAX_U128, EMULTIPLICATION); | ||
create_from_raw_value((unscaled_product as u128)) | ||
} | ||
|
||
|
||
/// Divide a u128 integer by a fixed-point number, truncating any | ||
/// fractional part of the quotient. This will abort if the divisor | ||
/// is zero or if the quotient overflows. | ||
|
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.
Why is this logic needed here? When you divide two fixed point values and want to return a fixed point value, no scaling is needed. I don't see any reason why if the remainder is non-zero, we should add
1
to the result.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.
Also check that divisor is non zero before performing the division.