
www.Usenet.com
| <-- __Chronological__ --> | <-- __Thread__ --> |
Does anyone know of any machines, that have a floating-point compare
instruction, where that instruction is not exact? That is, some of
the value bits of the floating-point numbers are ignored. Or, if
the compare is done internally as a subtract, the subtract results in
an underflow (so two different numbers near the minimum normalized
value, when subtracted produce a subnormal number) that is then flushed to zero, so compare equal.
double inexact_compare(double a, double b, int bits_to_skip)
{
// First the the regular difference:
double diff = b - a;// Shift this difference down by the number of bits to ignore: double scaled_diff = diff / ((double) (2 << bits_to_skip));
// Add it back to a, this will be a NOP if // the difference is small enough double a_delta = a + scaled_diff;
// Are the resulting values equal? if (a == a_delta) return 0.0;
// Otherwise, return the actual difference: return diff; }
double inexact_compare(double a, double b, double scale_factor) ... scaled_diff = diff * scale_factor;
Terje -- - <[EMAIL PROTECTED]> "almost all programming can be viewed as an exercise in caching"
| <-- __Chronological__ --> | <-- __Thread__ --> |