evm_sar

Implements EVM SAR over a two's-complement INT256 word: right shifts with sign-bit fill. Counts at least 256 return -1 for negative x and 0 otherwise. Negative SQL BIGINT counts throw Invalid Input Error: Shift amount must be non-negative. NULL input propagates to NULL.

Scalar function TypesEVM

Example

Runs locally

SELECT evm_sar(1::BIGINT, (-3)::INT256)::VARCHAR AS result;
-- => [{"result":"-2"}]

API reference

evm_sar(BIGINT, INT256) #

Arithmetic right shift with sign fill over a two's-complement 256-bit word.

Inputs

Name Type Use
shift BIGINT

Non-negative BIGINT bit count.

required positional
x INT256

Two's-complement INT256 word.

required positional

Returns

Name Type
result INT256

Arithmetic-shifted word. INT256 shifted value, sign-filled for large counts, or NULL for NULL input.