If you have the following C function used to determine if one number is a multiple of another to a valid arbirary value
#include <math.h>
#define TOLERANCE 0.0001
int IsMultipleOf(double x,double mod)
{
return(fabs(fmod(x, mod)) < TOLERANCE);
}
It works great, but profiling shows that it is very slow, to the extent that it has become a candidate for optimization. About 75% of the time is spent on modulo, and the rest on fabs. I'm trying to figure out a way to speed things up using something like a lookup table. The parameter xchanges regularly, but modrarely changes. The number of possible values of x is small enough so that the search space is not a problem, as a rule, it will be one of several hundred possible values. I can easily get rid of fabs, but I cannot find a reasonable alternative to the module. Any ideas on how to optimize the above?
Change . The code will run on a wide range of Windows desktop and mobile devices, so Intel, AMD on the desktop, and ARM or SH4 can be enabled on mobile devices. VisualStudio 2008 is a compiler.
source
share