title: Bigquery wrapping on overflow operation
body: <p>For one of my projects, I need basic INT64 arithmetic operations that wrap on overflow.</p>
  <p>Is there a more efficient way to accomplish this than casting INT64 to NUMERIC?</p>
  <pre><code>CREATE TEMP FUNCTION INT64_WRAPPING_OVERFLOW(x NUMERIC) AS
  (MOD(x+POW(CAST(2 as NUMERIC),63)+POW(CAST(2 as NUMERIC),64), POW(CAST(2 as NUMERIC),64))-POW(CAST(2 as NUMERIC),63));
  
  CREATE TEMP FUNCTION WRAPPING_OVERFLOW_SUBTRACT(intA INT64, intB INT64) AS
  (INT64_WRAPPING_OVERFLOW(CAST(intB as NUMERIC)-CAST(intA as NUMERIC)));
  
  CREATE TEMP FUNCTION WRAPPING_OVERFLOW_ADD(intA INT64, intB INT64) AS
  (INT64_WRAPPING_OVERFLOW(CAST(intB as NUMERIC)+CAST(intA as NUMERIC)));
  
  SELECT
  WRAPPING_OVERFLOW_SUBTRACT(9223372036854775807 , -9223372036854775808),
  -- returns 1
  WRAPPING_OVERFLOW_ADD(9223372036854775807 , 1),
  -- returns -9223372036854775808
  WRAPPING_OVERFLOW_SUBTRACT(-9223372036854775808 , 9223372036854775807),
  -- returns -1
  WRAPPING_OVERFLOW_ADD(-9223372036854775808 , -1),
  -- returns 9223372036854775807
  WRAPPING_OVERFLOW_SUBTRACT(-1 , 2),
  -- returns 3
  WRAPPING_OVERFLOW_ADD(2 , -1),
  -- returns 1
  WRAPPING_OVERFLOW_SUBTRACT(-43 , 45)
  -- returns 88
  </code></pre>