Skip to content

Commit

Permalink
✨ wadPow
Browse files Browse the repository at this point in the history
  • Loading branch information
transmissions11 committed Dec 1, 2022
1 parent 8d910d8 commit 3a752b8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/utils/SignedWadMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ function wadDiv(int256 x, int256 y) pure returns (int256 r) {
}
}

/// @dev Will not work with negative bases, only use when x is positive.
function wadPow(int256 x, int256 y) pure returns (int256) {
// Equivalent to x to the power of y because x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)
return wadExp((wadLn(x) * y) / 1e18); // Using ln(x) means x must be greater than 0.
}

function wadExp(int256 x) pure returns (int256 r) {
unchecked {
// When the result is < 0.5 we return zero. This happens when
Expand Down

1 comment on commit 3a752b8

@recmo
Copy link

@recmo recmo commented on 3a752b8 Dec 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Please sign in to comment.