Performs a fuzzy comparison of two numeric values.
Category: | Mathematical |
n * machine_precision * sum (abs(x1) + ... + abs(xn))
data _null_; x1 = -1/3; x2 = 22/7; x3 = -1234567891; x4 = 1234567890; /* Add the numbers in two different orders. */ sum1 = x1 + x2 + x3 + x4; sum2 = x4 + x3 + x2 + x1; diff = abs (sum1 - sum2); put sum1= / sum2= / diff=; /* Using only a fuzz value gives the wrong result. The fuzz value */ /* is 8 because there are four numbers in each sum, for a total of */ /* eight numbers. */ compfuzz = compfuzz (sum1, sum2, 8); put "fuzz only (wrong): " compfuzz=; /* Using a fuzz factor and a scale value gives the correct result. */ scale = abs(x1) + abs(x2) + abs(x3) + abs(x4); compfuzz = compfuzz (sum1, sum2, 8, scale); put "fuzz and scale (correct): " compfuzz=; run;