corey taylor wrote: > This is one method of fuzzy floating point equates using a > magnitude-based epsilon. > > const double fuzzyEpsilon = 0.000001; What value of fuzzyEpsilon is appropriate for float / long double ? I guess there is somkind of mathematical law in calculating it's value from sizeof(value_type) ... Or is 0.000001 just an educated guess ? > > /** > Computes an appropriate epsilon for comparing a and b. > */ > inline double eps(double a, double b) { > // For a and b to be nearly equal, they must have nearly > // the same magnitude. This means that we can ignore b > // since it either has the same magnitude or the comparison > // will fail anyway. > (void)b; If never seen this kind of cast before ... Is this statndard c/c++ or is it an gcc extension ? What is the effect of it ? > const double aa = abs(a) + 1; > if (aa == inf()) { > return fuzzyEpsilon; > } else { > return fuzzyEpsilon * aa; > } > } > > inline bool fuzzyEq(double a, double b) { > return (a == b) || (abs(a - b) <= eps(a, b)); > } > > corey > antonio