fixed_mul

Computes fixed-point multiplication as x * y / scale with a full 512-bit intermediate product. The caller owns the units and scale: this function does not require decimal, WAD, or Q-format inputs. It is pure and deterministic despite remaining registered VOLATILE for compatibility. NULL input propagates to NULL. A zero scale or a rounded quotient above UINT256 raises an error.

Example

Local

1
SELECT format_units(fixed_mul(2500000000000000000::UINT256, 3200000000000000000000::UINT256, 1000000000000000000::UINT256), 18) AS usd_value;
2
-- => [{"usd_value":"8000"}]
Notebook ready in readonly mode.

API reference

Exact signatures with descriptions, requirements, inputs, returns, and examples.

fixed_mul(UINT256, UINT256, UINT256) #

Returns floor(x * y / scale). The 512-bit product cannot overflow; the final UINT256 quotient can.

Inputs

Name Type Use
x UINT256

UINT256 factor expressed in the caller-selected units and scale.

required positional
y UINT256

UINT256 factor expressed in units compatible with x and scale.

required positional
scale UINT256

Non-zero UINT256 divisor removed after multiplying x and y.

required positional

Returns

Name Type
result UINT256

Floor-scaled product. UINT256 floor(x * y / scale), in the caller-derived output units; NULL when any argument is NULL.

fixed_mul(UINT256, UINT256, UINT256, TINYINT) #

Rounds the exact 512-bit ratio x * y / scale according to rounding. Rounding modes: 0=floor, 1=ceil, 2=trunc, 3=expand, 4=half-up. Because UINT256 is unsigned, floor and trunc both round down, ceil and expand both round up, and half-up rounds to nearest with ties upward. Compatibility behavior for unsupported TINYINT values is parity-based: odd values round up and even values round down.

Inputs

Name Type Use
x UINT256

UINT256 factor expressed in the caller-selected units and scale.

required positional
y UINT256

UINT256 factor expressed in units compatible with x and scale.

required positional
scale UINT256

Non-zero UINT256 divisor removed after multiplying x and y.

required positional
rounding TINYINT

TINYINT 0=floor, 1=ceil, 2=trunc, 3=expand, or 4=half-up; unsupported values retain parity behavior.

required positional

Returns

Name Type
result UINT256

Rounded scaled product. UINT256 rounded x * y / scale in caller-derived units; NULL when any argument is NULL. Rounding up can overflow an otherwise representable floor quotient.

Overload examples

Local SQL

1
SELECT fixed_mul(1000001::UINT256, 30::UINT256, 10000::UINT256, 1::TINYINT)::VARCHAR AS fee_raw;
2
-- => [{"fee_raw":"3001"}]

Related functions

Category and tags

Tag
Offline
Tag
Types