Optimized gas costs in ceilDiv (#4553)

This commit is contained in:
carter-ya
2023-11-23 23:31:14 +08:00
committed by GitHub
parent 0950532d9a
commit e5fb718d40
3 changed files with 18 additions and 6 deletions

View File

@ -16,10 +16,11 @@ contract MathTest is Test {
if (result == 0) {
assertEq(a, 0);
} else {
uint256 maxdiv = UINT256_MAX / b;
bool overflow = maxdiv * b < a;
assertTrue(a > b * (result - 1));
assertTrue(overflow ? result == maxdiv + 1 : a <= b * result);
uint256 expect = a / b;
if (expect * b < a) {
expect += 1;
}
assertEq(result, expect);
}
}