Skip to main content

ExtendedMath

This contract contains math related utilities that allows to compute fixed-point exponentiation or perform scaled arithmetic operations

Functions

powf

function powf(
int128 _x,
int128 _y
) internal returns (int128 _xExpy)

Computes x**y where both x and y are fixed-point numbers

Parameters

NameTypeDescription
_xint128
_yint128

mulPow

function mulPow(
uint256 value,
uint256 base,
uint256 exponent,
uint256 decimal
) internal returns (uint256)

Computes value * base ** exponent where all of the parameters are fixed point numbers scaled with decimal

Parameters

NameTypeDescription
valueuint256
baseuint256
exponentuint256
decimaluint256

scaledMul

function scaledMul(
uint256 a,
uint256 b,
uint256 _decimals
) internal returns (uint256)

Multiplies a and b scaling the result down by _decimals scaledMul(a, b, 18) with an initial scale of 18 decimals for a and b would keep the result to 18 decimals The result of the computation is floored

Parameters

NameTypeDescription
auint256
buint256
_decimalsuint256

scaledMul

function scaledMul(
uint256 a,
uint256 b
) internal returns (uint256)

Parameters

NameTypeDescription
auint256
buint256

scaledDiv

function scaledDiv(
uint256 a,
uint256 b,
uint256 _decimals
) internal returns (uint256)

Divides a and b scaling the result up by _decimals scaledDiv(a, b, 18) with an initial scale of 18 decimals for a and b would keep the result to 18 decimals The result of the computation is floored

Parameters

NameTypeDescription
auint256
buint256
_decimalsuint256

scaledDiv

function scaledDiv(
uint256 a,
uint256 b
) internal returns (uint256)

See scaledDiv(uint256 a, uint256 b, uint256 _decimals)

Parameters

NameTypeDescription
auint256
buint256

scaledPow

function scaledPow(
uint256 base,
uint256 exp,
uint256 _decimals
) internal returns (uint256)

Computes a**b where a is a scaled fixed-point number and b is an integer This keeps a scale of _decimals for a The computation is performed in O(log n)

Parameters

NameTypeDescription
baseuint256
expuint256
_decimalsuint256

scaledPow

function scaledPow(
uint256 base,
uint256 exp
) internal returns (uint256)

See scaledPow(uint256 base, uint256 exp, uint256 _decimals)

Parameters

NameTypeDescription
baseuint256
expuint256