muldiv
x * y / z with a 512-bit product: no overflow before division. UINT256 rounds down, INT256 truncates toward zero, unless a rounding mode is given. Errors when z is zero or result does not fit its type. NULL propagates. Native integer arguments fit both forms: cast them to UINT256 or INT256.
Example
Runs locally
API reference
muldiv(UINT256, UINT256, UINT256) #
Forms the full 512-bit product x * y, divides it by z, and returns the floor as UINT256.
Returns
| Name | Type |
|---|---|
result | UINT256 |
Floor quotient. UINT256 floor(x * y / z), or NULL when any input is NULL.
muldiv(UINT256, UINT256, UINT256, TINYINT) #
Computes (x * y) / z for UINT256 inputs using the supplied rounding mode. 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, or INT256 for a signed result, in the 512-bit product. | required positional |
y | UINT256 Same type as x, in the 512-bit product. | required positional |
z | UINT256 Non-zero, same type as x. | required positional |
rounding | TINYINT TINYINT mode 0=floor, 1=ceil, 2=trunc, 3=expand, or 4=half-up. | required positional |
Returns
| Name | Type |
|---|---|
result | UINT256 |
Rounded quotient. UINT256 rounded quotient; NULL when any input is NULL. Rounding can itself cause quotient overflow.
Overload examples
Runs locally
muldiv(INT256, INT256, INT256) #
512-bit product of INT256 magnitudes over |z|, sign carried separately, truncated toward zero as INT256 `/`.
Returns
| Name | Type |
|---|---|
result | INT256 |
Signed quotient. INT256 x * y / z truncated toward zero; NULL when any input is NULL. Quotient outside INT256 errors.
Overload examples
Runs locally
muldiv(INT256, INT256, INT256, TINYINT) #
INT256 x * y / z, exact, rounded by mode. Rounding modes: 0=floor (toward -inf), 1=ceil (toward +inf), 2=trunc (toward zero), 3=expand (away from zero), 4=half-up (nearest, ties toward +inf). Other modes error.
Inputs
| Name | Type | Use |
|---|---|---|
x | INT256 UINT256, or INT256 for a signed result, in the 512-bit product. | required positional |
y | INT256 Same type as x, in the 512-bit product. | required positional |
z | INT256 Non-zero, same type as x. | required positional |
rounding | TINYINT TINYINT mode 0=floor, 1=ceil, 2=trunc, 3=expand, or 4=half-up (ties toward positive infinity). | required positional |
Returns
| Name | Type |
|---|---|
result | INT256 |
Rounded signed quotient. INT256 rounded quotient; NULL when any input is NULL. Quotient outside INT256 or unknown mode errors.
Overload examples
Runs locally