Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/StdMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ library stdMath {
}

function percentDelta(uint256 a, uint256 b) internal pure returns (uint256) {
// Prevent division by zero
require(b != 0, "stdMath: percentDelta divisor is zero");
uint256 absDelta = delta(a, b);

return absDelta * 1e18 / b;
Expand All @@ -37,6 +39,8 @@ library stdMath {
function percentDelta(int256 a, int256 b) internal pure returns (uint256) {
uint256 absDelta = delta(a, b);
uint256 absB = abs(b);
// Prevent division by zero
require(absB != 0, "stdMath: percentDelta divisor is zero");

return absDelta * 1e18 / absB;
}
Expand Down