The Alteryx Community is a finalist in three 2026 CMX Awards! Help us win Customer Support Community, Most Engaged Community, and User Group Program of the Year - vote now! (it only takes about 2 minutes) before January 9.
ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests Early 2026. Make sure to check your account preferences in my.alteryx.com to make sure you have filled out your security questions. Learn more here
Start Free Trial

Engine Works

Under the hood of Alteryx: tips, tricks and how-tos.
ned_blog
8 - Asteroid

It seems like a very straight forward thing to do - comparing numbers. It ends up much more complicated than people think. The problem is that 2 numbers that look the same might have be created via very slightly different mathematical functions and might differ only in the 16th decimal place. This is compounded by the fact that all floating point numbers are actually stored as base 2, not base 10.

 

In the past I have suggested to people that they write a formula like:

 

abs(a-b)<0.00001

 

That works for small numbers, but as numbers get very large (> 10^14 or so), that stops working. The reason it stops working is because a floating point number only stores about 17 significant digits of information. For a big number that 17th digit starts getting pretty big, even though for comparison it is trivial.

 

Alteryx 5.0 adds 2 new functions to the formula language: CompareEpsilon & CompareDigits

 

CompareEpsilon is exactly like the example above. You could rewrite it to:

 

CompareEpsilon(a,b,0.00001)

 

It is just a short cut to make what is being done more clear.

 

CompareDigits is the more useful function. CompareDigits(a,b,10) will return true if the 1st 10 significant digits of a and b are the same. That works equally well for comparing 1.7==1.7 as 1.7e50==1.7e50. CompareDigits is definitely the preferred way of comparing two numbers that may be anything other than integers.

Comments