muldiv
Computes floor(x * y / z) with the product formed in 512 bits. Errors when z is zero or when the quotient does not fit UINT256. NULL input propagates to NULL.
Example
Local
API reference
Exact signatures with descriptions, requirements, inputs, returns, and examples.
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 factor in the 512-bit product. | required positional |
y | UINT256 UINT256 factor in the 512-bit product. | required positional |
z | UINT256 Non-zero UINT256 divisor. | 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
Local SQL
Related functions
Category and tags
- Category
- EVM utilities
- Tag
- Types
- Tag
- EVM