The issue is that that potential returns from the _expression_ is evaluated, and that leads to the division by zero.  The same thing can happen with other illegal expressions (e.g., log of a non-positive number).  Your workaround can be acceptable if you don't mind the small error.  You can make the epsilon smaller, but then run into losing it due to roundoff errors.

Another approach is to fool the evaluation procedure by only changing the results when the divisor is 0.  For your example, consider
$0==0 ? 0.0 : 1.0/(($0==0 ? 1.0 : 0.0) + $0)







Please respond to [email protected]

Sent by: [EMAIL PROTECTED]

To: <[email protected]>
cc:
Subject: [opendx-users] Compute question




Hey there,

this a problem with the Compute model that I have several times run into:

Why does the following dxscript not work :
-----------------------------------B
data = "" -5 -5 ],[1 1 1],[10 10 10],0);
pos = Mark(data,"positions");
mag = Compute("mag($0)",pos);
inv = Compute("$0 > 0 ? 1.0/$0 : 0.0",mag);
-------------------

As you can see, I want to inverse a data field containing a zero value.
To prevent a devision by zero error, I use a ternary operator that checks
if the data is greater than zero before inverting, and else sets zero.

This construct apparently is not allowed, because I still get a
division by zero error message.

Until so far I have solved the problem by adding a very small number to the
data field, like:
inv     = Compute("$0 > 0 ? 1.0/($0+.000001) : 0.0",mag);

but this is not very clean, because it also affects the other data.

Does anybody has a better solution?

Thanks in advance!

Regards

Eelco


Reply via email to