Quote Originally Posted by robatino
I used the dreaded "==". It works for inputs up to about 15 or 16 decimal digits, assuming the arithmetic is IEEE 754 (if the input is longer than that, it thinks it's always an integer). Suppose I modified it to use the delta method (either on the difference between d and floor(d), or the difference between 1 and d/floor(d)). Okay, how do I choose delta? Is there a portable way? No. My point is that this is a special case, and the general rule "never use == for floats" doesn't necessarily apply.
hmmm how about FLT_EPSILON and DBL_EPSILON?

something like this, made quickly

Code:
int compareEqual(float a, float b)
{
  if (abs(a-b) <= (max(abs(a), abs(b)) * FLT_EPSILON)
  {
    return 1;
  }
  else
  {
    return 0;
  }
}