Loading

divmul

Scalar function

Computes (x * d) / y using 512-bit intermediate to avoid overflow. Inverse of muldiv. Useful for price calculations.

divmul(UINT256, UINT256, UINT256)

Parameters

Returns

Name Type
result UINT256
1
SELECT divmul(token_amount, price, '1000000000000000000'::UINT256);
Notebook ready in readonly mode.

divmul(UINT256, UINT256, UINT256, TINYINT)

Parameters

Name Type
x UINT256
y UINT256
d UINT256
rounding TINYINT

Returns

Name Type
result UINT256
1
SELECT divmul(debt, rate, WAD, 1) AS debt_rounded_up;
Notebook ready in readonly mode.