title: C: Why fabs giving weird result while comparing floating point numbers?
body: <p>I have a small simple code to compare 2 floating point numbers:</p>
  
  <p>I tried using fabs but it gives wrong weird result. What is the mistake, and what is the correct form?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;float.h&gt;
  
  void compareFloat(double a1, double a2)
  {
     if(fabs(a1 - a2) &lt; DBL_EPSILON)
         printf("a1 is smaller\n");
     else
         printf("a1 is larger\n");
  }
  
  int main()
  {
   float a1=0.0000004f, a2=0.0005f;
   compareFloat(a1, a2);
  }
  </code></pre>
  
  <p>What is the mistake in this code? It always prints <code>a1 is smaller</code> even if i set a1=0.004f and a2=0.0005f</p>