>>128
valが整数なら
@val1 = @val2 % @val3
とか?