title: Time Limit Exceeded with abs() in a C++ Program
body: <p>I encounter a problem with the abs() in a program. When I use the code:</p>
  
  <pre><code>long long dvd = abs(dividend), dvs = abs(divisor);
  </code></pre>
  
  <p>it been reported "Time Limit Exceeded"</p>
  
  <p>when use:</p>
  
  <pre><code>long long dvd = dividend, dvs = divisor;
  dvd = abs(dvd);
  dvs = abs(dvs);
  </code></pre>
  
  <p>everything is okay...</p>
  
  <p>The full code is following:</p>
  
  <pre><code>class Solution {
  public:
      int divide(int dividend, int divisor) {
      long long dvd = dividend, dvs = divisor;
      dvd = abs(dvd);
      dvs = abs(dvs);
      long long result = 0;
  
      while (dvd &gt;= dvs) {
          long long temp = dvs;
          int i = 0;
          while (dvd &gt;= temp) {
              temp = temp &lt;&lt; 1;
              i++;
          }
          dvd -= dvs &lt;&lt; (i-1);
          result += (long long)1 &lt;&lt; (i-1);
      }
  
      result = ((long long)dividend &gt; 0 ^ (long long)divisor &gt; 0) ? -result : result;
  
      if (result &gt; (1&lt;&lt;31) - 1)
          return (1&lt;&lt;31) - 1;
  
      return result;
    }
  };
  </code></pre>
  
  <p>Could someone help to explain what happens with <code>abs()</code> here?</p>