Usage Note 15553: COMPFUZZ function available for error analysis beginning in SAS 9.2
Beginning in SAS 9.2, the COMPFUZZ function is available to perform a
"fuzzy" comparison of two numeric values. This function is not
documented to customers. The following information can be sent to
customers who are performing numerical error analysis.
COMPFUZZ Function
This function is used for numerical error analysis, performing
a fuzzy comparison of two numeric values.
Category: Mathematical
Syntax
COMPFUZZ(value1, value2 <, fuzz <, scale>>)
Arguments
value1
specifies the first of two numeric values to be compared.
value2
specifies the second numeric value to be compared.
fuzz
is a nonnegative numeric value that specifies the relative
threshold for comparisons. Values greater than or equal to one
are treated as multiples of the machine precision. To determine
machine precision, see the CONSTANT('MACEPS') function.
Default: 1024
scale
specifies the scale factor used in computing the threshold.
Default: MAX (ABS (value1), ABS (value2))
Details
The COMPFUZZ function returns the following values:
-1 if value1 < value2 - threshold
0 if ABS(value1 - value2) <= threshold
1 if value1 > value2 + threshold
where
threshold = fuzz * ABS(scale) /* if 0 <= fuzz < 1 */
threshold = fuzz * ABS(scale) * CONSTANT('MACEPS'
/* if 1 <= fuzz < 1 / CONSTANT('MACEPS') */
COMPFUZZ avoids floating point underflow or overflow, which are
conditions that can occur during a mathematical operation if
there are too many digits to the right or left of the decimal
point, causing numeric imprecision. Altering the values of the
fuzz and scale arguments provides the ability to compare the
results of different algorithms with the appropriate error
analysis technique.
Comparisons
The COMPFUZZ function compares two floating point numbers and
returns a value based on the comparison. The ROUND function
rounds an argument to a value that is very close to a multiple
of a second argument. The result might not be an exact multiple
of the second argument. Please see Technical Support Document
TS 230 and TS654 for details on floating point representation,
imprecision caused by loss of significance and representation
error.
Examples
In floating point arithmetic, the value of a sum sometimes
depends on the order in which the numbers are added. One
approximate error bound for the sum of n numbers, x1 through xn
is expressed by the following relationship:
n * machine_precision * sum (abs(x1) + ... + abs(xn))
To compare sums of n floating point numbers with the COMPFUZZ
function, you can therefore use n as the fuzz value and the sum
of the absolute values as the scale factor, as shown in the
following DATA step:
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;
SAS writes the following output to the log:
sum1=1.8095238095
Operating System and Release Information
| SAS System | Base SAS | Microsoft Windows Server 2003 Enterprise Edition | 9.2 | | | |
| Microsoft Windows XP 64-bit Edition | 9.2 | | | |
| Microsoft Windows XP Professional | 9.2 | | | |
| Microsoft Windows Server 2003 Standard Edition | 9.2 | | | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 | | | |
| Microsoft Windows 2000 Server | 9.2 | | | |
| Microsoft Windows Server 2003 Datacenter Edition | 9.2 | | | |
| Microsoft Windows 2000 Professional | 9.2 | | | |
| Microsoft Windows 2000 Datacenter Server | 9.2 | | | |
| Microsoft Windows 2000 Advanced Server | 9.2 | | | |
| 64-bit Enabled Solaris | 9.2 | | | |
| Solaris | 9.2 | | | |
| z/OS | 9.2 | | | |
| HP-UX IPF | 9.2 | | | |
| HP-UX | 9.2 | | | |
| Linux | 9.2 | | | |
| Tru64 UNIX | 9.2 | | | |
| 64-bit Enabled AIX | 9.2 | | | |
| OpenVMS Alpha | 9.2 | | | |
| 64-bit Enabled HP-UX | 9.2 | | | |
| AIX | 9.2 | | | |
*
For software releases that are not yet generally available, the Fixed
Release is the software release in which the problem is planned to be
fixed.
| Type: | Usage Note |
| Priority: | low |
| Topic: | SAS Reference ==> Functions SAS Reference ==> Functions ==> Mathematical
|
| Date Modified: | 2008-12-23 11:13:10 |
| Date Created: | 2005-06-15 15:05:18 |