Loading

muldiv

Scalar function

Computes (x * y) / z using 512-bit intermediate to avoid overflow. Essential for DeFi calculations like token swaps and price computations.

muldiv(UINT256, UINT256, UINT256)

Parameters

Returns

Name Type
result UINT256
1
SELECT muldiv(amount, price, '1000000000000000000'::UINT256) AS scaled_amount;
Notebook ready in readonly mode.

muldiv(UINT256, UINT256, UINT256, TINYINT)

Parameters

Name Type
x UINT256
y UINT256
z UINT256
rounding TINYINT

Returns

Name Type
result UINT256
1
SELECT muldiv(amount, fee_bps, 10000::UINT256, 1) AS fee_rounded_up;
Notebook ready in readonly mode.