Solved

AttributeManager Arithmetic Editor - Testing floats for equality?

  • 10 September 2021
  • 2 replies
  • 0 views

Badge +1

How in FME would you check that two floats are "close", given testing floats for equality can be a challenge?

 

e.g. "-23.123" as listed in an XLS compared to "-23.12300005" stored in a point feature class?

 

In Python I use the math.isClose() or assertAlmostEqual()

 

Thanks

 

icon

Best answer by debbiatsafe 11 September 2021, 01:40

View original

2 replies

Userlevel 3
Badge +17

math.isClose() uses this formula to evaluate whether two values are close or not:

abs(a-b) <= max( rel_tol * max(abs(a), abs(b)), abs_tol )

You can try implementing this formula within an AttributeManager using math operators and math functions. Using the default values for rel_tol and abs_tol, it would look something like this:

@Evaluate(@abs(@Value(fc)-@Value(xls)) <= @max(@exp(-09) * @max(@abs(@Value(fc)), @abs(@Value(xls))), 0.0))

A result of 1 would be true (close). 0 would indicate false (not close). I hope it helps!

Badge +1

Thanks Debbi!

Reply