You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the library provides a pow(int128 x, uint256 y) function to calculate x raised to the power of y, where x is a signed 64.64 fixed-point number and y is an unsigned integer. This function is great for scenarios where the exponent is an integer.
However, there are use cases where it would be beneficial to have a power function where both the base and the exponent are signed 64.64 fixed-point numbers. Essentially, a function with this signature: pow(int128 x, int128 y)
Such a function would allow raising a signed 64.64 fixed-point number to the power of another signed 64.64 fixed-point number. This would be very useful for calculations involving fractional exponents, and would increase the versatility of the library.
Implementing this function might involve using the existing ln(int128 x) and exp(int128 x) functions, since:
function pow(int128x, int128y) internalpurereturns (int128) {
require(x >=0, "Negative base not allowed");
if (x ==0) {
require(y >0, "0^0 is undefined");
return0;
}
returnexp(mul(y, ln(x)));
// OR(whichever is more gas cheap)returnexp_2(mul(y, log_2(x)));
}
The text was updated successfully, but these errors were encountered:
Currently, the library provides a
pow(int128 x, uint256 y)
function to calculate x raised to the power of y, where x is a signed 64.64 fixed-point number and y is an unsigned integer. This function is great for scenarios where the exponent is an integer.However, there are use cases where it would be beneficial to have a power function where both the base and the exponent are signed 64.64 fixed-point numbers. Essentially, a function with this signature:
pow(int128 x, int128 y)
Such a function would allow raising a signed 64.64 fixed-point number to the power of another signed 64.64 fixed-point number. This would be very useful for calculations involving fractional exponents, and would increase the versatility of the library.
Implementing this function might involve using the existing
ln(int128 x)
andexp(int128 x)
functions, since:Example implementation:
The text was updated successfully, but these errors were encountered: