Example: Comparing Floating Point Values - Teradata Vantage - Analytics Database

SQL Data Types and Literals

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Analytics Database
Teradata Vantage
Release Number
17.20
Publication Date
June 2022
Content Type
Data Types
SQL Reference
Publication ID
B035-1143-172K
ft:locale
en-US
ft:lastEdition
2025-11-06
dita:mapPath
uds1628112204571.ditamap
dita:ditavalPath
qkf1628213546010.ditaval
ft:sourceId
dita
dita:id
exs1472253032394
lifecycle
latest
Product Category
Teradata Vantageā„¢

Calculations involving floating point values often produce results that are not what you expect. If you perform a floating point calculation and then compare the results against some expected value, it is unlikely that you get the intended result. Consider the results of Example: Non-Associativity of Floating Point Arithmetic.

Instead of comparing the results of a floating point calculation, make sure that the result is greater or less than what is needed, with a given error. Here is an example of how to rewrite the statement in Example: Non-Associativity of Floating Point Arithmetic and achieve the desired results:

SELECT i, SUM(a) as sum_a, SUM(b) as sum_b
FROM t1
GROUP BY i
HAVING ABS(sum_a - sum_b) > 1E-10;