# evm_clamp

Constrains x to the inclusive range [lo, hi] when lo <= hi. For compatibility, reversed bounds lo > hi return lo; reversed bounds do not describe a valid interval. NULL input propagates to NULL.

Canonical HTML: <https://determica.com/docs/functions/evm_clamp>

- Kind: scalar function
- Category: [EVM utilities](/docs/category/evm-utilities.md)
- Tags: Types, EVM

Constrains x to the inclusive range [lo, hi] when lo <= hi. For compatibility, reversed bounds lo > hi return lo; reversed bounds do not describe a valid interval. NULL input propagates to NULL.

## Overload 1: evm_clamp(UINT256, UINT256, UINT256)

```sql
evm_clamp(UINT256, UINT256, UINT256)
```

Returns max(lo, min(hi, x)) for valid bounds; current compatibility behavior returns lo for lo > hi.

- Kind: scalar
- Execution context: Offline
- Behavior: Transform
- Execution modes: Offline
- Input shape: Scalar Arguments
- Planning contract: Runtime
- Cardinality: One Per Input
- Determinism: Deterministic
- Return shape: Scalar
- Schema stability: Fixed
- Stability: Stable
- Side effects: None documented

### Inputs

- `x` (UINT256; required; positional) — UINT256 value to constrain.
- `lo` (UINT256; required; positional) — Inclusive UINT256 lower bound.
- `hi` (UINT256; required; positional) — Inclusive UINT256 upper bound.

### Returns

Constrained value

Constrained UINT256 value, or NULL when any input is NULL.

- `result` (UINT256)

Constrained value. Constrained UINT256 value, or NULL when any input is NULL.

### Examples

_Local SQL · Local_

```sql
SELECT evm_clamp(7::UINT256, 10::UINT256, 5::UINT256)::VARCHAR AS result;
-- => [{"result":"10"}]
```

## Related functions

- [muldiv](/docs/functions/muldiv.md) — See Also
- [fixed_mul](/docs/functions/fixed_mul.md) — See Also
- [fixed_div](/docs/functions/fixed_div.md) — See Also
