@approx(x:numeric, y:numeric) ; listable
The function call can also be written with the special syntax
(x ~ y)
note that the parenthesis are mandatory.
This predicate returns true if
abs((x - y)/max(x, y)) < $APPROX_RATIO
The predefined variable
$APPROX_RATIO is initalized to
(x ~ y) means
y differ by less than 10%. By changing the
value of the variable , one changes the level of approximation for the
following calls to
Notice that using this function to check if a number is near zero is a
(x ~ 0) results in the comparaison of
-1 (as a result
abs(x)/x) even if
x is zero.
If one argument is a tab and the other is a scalar u, the scalar argument is extended to tab if (all elements of the extension are equal to u) and the predicate returns true if it hold pointwise for all elements of the tabs. For example
(tab[1, 2] ~ 1.02)
false because we don’t have
(2 ~ 1.02).