title: What is different about C++ math.h abs() compared to my abs()
body: <p>I am currently writing some glsl like vector math classes in C++, and I just implemented an <code>abs()</code> function like this:</p>
  
  <pre><code>template&lt;class T&gt;
  static inline T abs(T _a)
  {
      return _a &lt; 0 ? -_a : _a;
  }
  </code></pre>
  
  <p>I compared its speed to the default C++ <code>abs</code> from <code>math.h</code> like this:</p>
  
  <pre><code>clock_t begin = clock();
  for(int i=0; i&lt;10000000; ++i)
  {
      float a = abs(-1.25);
  };
  
  clock_t end = clock();
  unsigned long time1 = (unsigned long)((float)(end-begin) / ((float)CLOCKS_PER_SEC/1000.0));
  
  begin = clock();
  for(int i=0; i&lt;10000000; ++i)
  {
      float a  = myMath::abs(-1.25);
  };
  end = clock();
  unsigned long time2 = (unsigned long)((float)(end-begin) / ((float)CLOCKS_PER_SEC/1000.0));
  
  std::cout&lt;&lt;time1&lt;&lt;std::endl;
  std::cout&lt;&lt;time2&lt;&lt;std::endl;
  </code></pre>
  
  <p>Now the default abs takes about 25ms while mine takes 60. I guess there is some low level optimisation going on. Does anybody know how <code>math.h</code> <code>abs</code> works internally? The performance difference is nothing dramatic, but I am just curious!</p>