Reverse positive and negative integers without using built-in functions. Implement reverse_integer(x) using arithmetic operations only, without converting the integer to a string or using built-in reversal, absolute-value, or digit-processing functions. Return the integer with its digits reversed while preserving its sign; return 0 for input 0.
def reverse_integer(x):