Skip to content

Commit 3a752b8

Browse files
✨ wadPow
1 parent 8d910d8 commit 3a752b8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/utils/SignedWadMath.sol

+6
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ function wadDiv(int256 x, int256 y) pure returns (int256 r) {
8787
}
8888
}
8989

90+
/// @dev Will not work with negative bases, only use when x is positive.
91+
function wadPow(int256 x, int256 y) pure returns (int256) {
92+
// Equivalent to x to the power of y because x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)
93+
return wadExp((wadLn(x) * y) / 1e18); // Using ln(x) means x must be greater than 0.
94+
}
95+
9096
function wadExp(int256 x) pure returns (int256 r) {
9197
unchecked {
9298
// When the result is < 0.5 we return zero. This happens when

0 commit comments

Comments
 (0)