title: Designing function f(f(n)) == -n
body: <p>A question I got on my last interview:</p>
  
  <blockquote>
    <p>Design a function <code>f</code>, such that:</p>
  
  <pre><code>f(f(n)) == -n
  </code></pre>
    
    <p>Where <code>n</code> is a 32 bit <strong>signed integer</strong>; you can't use complex numbers arithmetic.</p>
    
    <p>If you can't design such a function for the whole range of numbers, design it for the largest range possible.</p>
  </blockquote>
  
  <p>Any ideas?</p>