Differences in floating-point error tolerances

For queries that involve floating-point aggregates, you can expect IBM Db2 Analytics Accelerator for z/OS® to produce results that are different from those delivered by inhouse Db2 for z/OS processing.

Reason

You know that the same query processed twice by Db2 for z/OS can give you different results. This is due to the fact that the results depend on the order in which the rows or tuples are processed. It is not possible to determine the order that Db2 will choose beforehand.

In the case of IBM Db2 Analytics Accelerator for z/OS, another sort of result deviation occurs, which is caused by the different methods of representation for floating-point numbers. Db2 for z/OS uses hexadecimal floating-point (HFP) numbers, whereas IBM Db2 Analytics Accelerator for z/OS uses IEEE754 floating-point numbers.

When a query is routed from Db2 for z/OS to IBM Db2 Analytics Accelerator for z/OS, all processing takes place on the accelerator.

The main difference between these two methods is the base or radix of the exponential part. HFP uses a base of 16. IEEE754 uses a base of 2. The base of 16 requires the exponent of HFP numbers to be increased in steps of 4 during the calculation of an aggregate. IEEE754 numbers, on the other hand, need to be increased just in steps of 1. The multiplier in front of the exponent (mantissa) of an HFP number loses 4 bits at the right end each time the exponent is increased. The mantissa of IEEE754 numbers loses just 1 bit. The difference in error thus lies in the difference of three bits, and the amount per step depends on the values of these. If the values of the three bits are all zero, the error difference is also zero. If all values are 1, the difference in error is maximized. Because of the lower exponential increase per step, IEEE754 is the more precise method of representation.

Whether the difference in precision matters much mainly depends on the number of rows or tuples (n) used for floating-point aggregates. Naturally, if n gets higher, the result deviation or error increases, too. How high the total deviation will be is hard to quantify as it further depends on the type of the mathematical function that is used (compare, for example, a simple addition with an operation that takes the square of each number involved).

Important: In contrast to HFP numbers of the type REAL in Db2 for z/OS, which might range from -7.2E+75 to +7.2E+75, IEEE754 is only capable of processing REAL floating point numbers between -3.4E+38 and 3.4E+38. This means that it is not possible to load an accelerator-shadow table with REAL values outside the range of -3.4E+38 to 3.4E+38.
Also bear in mind that HFP and IEEE754 have different minimum and maximum values for REAL and DOUBLE numbers:
Table 1. Minimum and maximum REAL and DOUBLE values (HFP and IEEE754)
  HFP (Db2 for z/OS) IEEE754 (IBM Db2 Analytics Accelerator for z/OS)
  REAL DOUBLE REAL DOUBLE
Min. ~ -7.2 * 10+75 ~ -7.2 * 10+75 ~ -3.4 * 10+38 ~ -1.79 * 10+308
Max. ~ +7.2 * 10+75 ~ +7.2 * 10+75 ~ +3.4 * 10+38 ~ +1.79 * 10+308
Min. positive ~ +5.4 * 10-79 ~ +5.4 * 10-79 ~ +1.18 * 10-38 ~ +3.4 * 10-308
Max. negative ~ -5.4 * 10-79 ~ -5.4 * 10-79 ~ -1.18 * 10-38 ~ -3.4 * 10-308