title: Faster way of finding multiple of double
body: <p>If have the following C function, used to determine if one number is a multiple of another to an arbirary tolerance</p>
  
  <pre><code>#include &lt;math.h&gt;
  
  #define TOLERANCE 0.0001
  
  int IsMultipleOf(double x,double mod)
  {
      return(fabs(fmod(x, mod)) &lt; TOLERANCE);
  }
  </code></pre>
  
  <p>It works fine, but profiling shows it to be very slow, to the extent that it has become a candidate for optimization.  About 75% of the time is spent in <code>modulo</code> and the remaining in <code>fabs</code>.  I'm trying to figure a way of speeding things up, using something like a look-up table.  The parameter <code>x</code> changes regularly, whereas <code>mod</code> changes infrequently.  The number of possible values of x is small enough that the space for a look-up would not be an issue, typically it will be one of a few hundred possible values.  I can get rid of the <code>fabs</code> easily enough, but can't figure out a reasonable alternative to the modulo.  Any ideas on how to optimize the above?</p>
  
  <p><strong>Edit</strong>  The code will be running on a wide range of Windows desktop and mobile devices, hence processors could include Intel, AMD on desktop, and ARM or SH4 on mobile devices.  VisualStudio 2008 is the compiler.</p>