def smod(evm: Evm) -> None: """ Signed modulo remainder of the top two elements of the stack. Pushes the result back on the stack. Parameters ---------- evm : The current EVM frame. Raises ------ StackUnderflowError If `len(stack)` is less than `2`. OutOfGasError If `evm.gas_left` is less than `5`. """ evm.gas_left = subtract_gas(evm.gas_left, GAS_LOW) x = pop(evm.stack).to_signed() y = pop(evm.stack).to_signed() if y == 0: remainder = 0 else: remainder = get_sign(x) * (abs(x) % abs(y)) push(evm.stack, U256.from_signed(remainder))
def sdiv(evm: Evm) -> None: """ Signed integer division of the top two elements of the stack. Pushes the result back on the stack. Parameters ---------- evm : The current EVM frame. Raises ------ StackUnderflowError If `len(stack)` is less than `2`. OutOfGasError If `evm.gas_left` is less than `5`. """ evm.gas_left = subtract_gas(evm.gas_left, GAS_LOW) dividend = pop(evm.stack).to_signed() divisor = pop(evm.stack).to_signed() if divisor == 0: quotient = 0 elif dividend == -U255_CEIL_VALUE and divisor == -1: quotient = -U255_CEIL_VALUE else: sign = get_sign(dividend * divisor) quotient = sign * (abs(dividend) // abs(divisor)) push(evm.stack, U256.from_signed(quotient))