Best Practice for IF Functions in Equations
When you use the IF
function and assign a
value
to the Global Variable
or the value to compare with, you may
get an unexpected result because of the floating-point math done by equations.
SOLIDWORKS uses floating-point math to compare values. For example, if you
specify a Global Variable
of 2.2, SOLIDWORKS might evaluate it as 2.2000001 or 2.1999998. In such
cases, the comparison returns 0 (False)
instead of 1 (True).
Under Value/Equations, create the IF statement as follows:
= iif ( abs ("GV" - 2.2) <= "tolerance", 1, 0)
Global Variable
GV minus itself is less than or equal to the
tolerance, so the equation Evaluates to
1, the expected result. You use the abs()
(absolute) function to get the positive value of
the subtraction operation to compare to the tolerance. If one or both of the
comparators in the equation have a negative value, use the abs()
function to obtain the desired logic.