What's new

KScript Editor Caveat

Big Bob

Senior Member
I have recently discovered that the KScript Editor (KSE) doesn't do negative division correctly. Take a look at this little test script.

on init
``declare $MinusFive := -5
``if ($MinusFive/4 = -5/4)
````message("Equal")
``else
````message("Not Equal")
``end if
end on


Paste the above code into Kontakt and hit Apply. Note the status line reads 'Equal'.

Now, compile the above code in the KSE (with Optimization enabled) and then paste the clipboard into Kontakt and hit Apply. Note that the status line now reads 'Not Equal'. :shock:

With optimization enabled, the KSE evaluates constant expressions before passing the result on to the KSP. But, expressions containing variables are passed directly to the KSP for evaluation. And, since the KSE does negative division differently from the KSP, expressions with constants can evaluate differently from expressions with variables containing the same values.

This problem has largely gone unnoticed since only division with a negative quotient can cause it. However, you should be aware of this potential problem with optimization because it may someday bite you (as it did me the other day :lol: ).

But, for heavens sake, don't stop using the 'Optimize compiled code' option just because of this. The optimization feature of the KSE is far too valuable to give up just for this rare situation.

Meanwhile, I'll try to report this problem to Nils if I can get his attention. :roll:

Rejoice,

Bob
 
Top Bottom