fixed_div
Computes fixed-point division as x * scale / y 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 y or a rounded quotient above UINT256 raises an error.
Example
Local
API reference
Exact signatures with descriptions, requirements, inputs, returns, and examples.
fixed_div(UINT256, UINT256, UINT256) #
Returns floor(x * scale / y). The 512-bit product cannot overflow; the final UINT256 quotient can.
Returns
| Name | Type |
|---|---|
result | UINT256 |
Floor-scaled quotient. UINT256 floor(x * scale / y), in the caller-selected result scale; NULL when any argument is NULL.
fixed_div(UINT256, UINT256, UINT256, TINYINT) #
Rounds the exact 512-bit ratio x * scale / y 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 value expressed in caller-selected units. | required positional |
y | UINT256 Non-zero UINT256 divisor expressed in units compatible with x. | required positional |
scale | UINT256 UINT256 factor applied before division to select the result scale. | 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 quotient. UINT256 rounded x * scale / y in the caller-selected scale; NULL when any argument is NULL. Rounding up can overflow an otherwise representable floor quotient.
Overload examples
Local SQL
Related functions
Category and tags
- Category
- Fixed-point and AMM math
- Tag
- Fixed Point Math
- Tag
- Deterministic
- Tag
- Offline
- Tag
- Types