BUG in Dynamic Component "IF" function evaluation

There seems to be a bug in the way Dynamic Component evaluates the results of an “IF” function. It appears to be evaluating the implied “then” section, even when it should not because the condition has already been met.

For example, I am trying to avoid a “division by zero” error by checking if the divisor is zero first, then only doing the math if it is not, yet the math gets done anyway, and thus I get the “DIV/0” error regardless!

Here’s the simplest possible way of reproducing this bug. Create two attributes:

ThisIsZero = 0
ThisIsZeroCheck = IF(ThisIsZero=0 , 1, 100/ThisIsZero)

The final part of that should never be evaluated (thus avoiding the error) since the attribute “ThisIsZero” is in fact zero, so it should never attempt to evaluate “100/ThisIsZero” … yet SketchUp evaluates it anyway, and reports “DIV/0”. The evaluation should stop at the first term, as soon as it figures out that “ThisIsZero” has a value of zero, and return the value “1”. There is no need to evaluate anything further, since the condition has been met.

It also occurs to me that if SketchUp really is evaluating every part of every “IF” function in a model, including the parts that are not relevant, that would go a long way to explaining why it is so slow on large, complex models! The speed could increase quite a bit if it didn’t bother evaluating things that don’t need evaluating…

Either that, or there’s something major that I’m missing here! Why would it return a “DIV/0” error, when it should not even be trying to do that, because the condition for doing so was not met?

Yes, computers have no overview, were as humans directly do not bother to evaluate, computers can’t.
They need to process all possible options.

The thing is, the language used in the Dynamic Components formulas is not a real computer programming language like C, Basic or Ruby. The extenion might be written in Ruby, the things you write aren’t parsed directly. It is ‘evaluated’ first, meaning it will translate into real Ruby code or use the statements as ‘parameters’ in functions and modules. It wil process the whole formula, unlike actual computer languages.

Am I close, @DanRathbun ?

You’re right “on the money” Jack.

We’d have to use the following pattern to “validate” a value …

Divisor = IF( Value = 0 , 1, Value )
Ratio = Whole / Divisor
1 Like