Dividing by zero in Expressions.
Have anything divided by zero, default to zero value instead of undefined.
In expressions when you divide by zero, it causes the expression to break. it would be cool if AE was smart enough to ignore this and just pretend that anything divided by zero had the value of zero. so we don't have to put if/then statements into our code to avoid this.
an example is if you are using expressions to keep the stroke of a shape layer constant as it scales. the expression looks somewhat like this.
stroke/scale/100
if scale is zero, it breaks, but if the scale of the layer is zero, you can't see it anyways and so having it automatically have a value of zero would be just fine.
Change my mind.
5 comments
-
Moritz Bechtold commented
The limit of a devision by zero is infinity.
I do understand your problem but neither is it appropriate to ignore bad code nor does the solution make sense. Maybe the linear or ease function helps in your case?
-
Nick R. commented
Mikey's suggestion of setting Undefined to something else by default would be a nice workaround. If that were in preferences with a checkbox to still throw up an error, or just throw and error if you leave the default blank would be great.
Personally I just make sure to have some code in the expression for if the variable I'm dividing with is 0 then do whatever is needed for the specific expression.
For keeping expression code more concise though it seems like a good idea.
-
Mikey Borup commented
Zack, I see your point for debugging. but what if it is not broken, and this is the way you have to do it? like in the scale example? All I'm saying is that how it is now, if you have to have something divided by a variable that could at one point be zero, most of the time having it equal zero will be the best outcome. right now we have to put in checks to solve for that, which you could still do.
So if you come across a situation where you divide by zero what do you currently do? because for me I multiply it by a decimal (resulting in zero) or do an if/then statement to turn it to zero.
What if "undefined" was treated more like a variable, that by default is set to undefined, but you could set it to something else if you wanted?
-
Zack Lovatt commented
Please, no. If something's broken, tell me it's broken instead of hiding that and leaving me to guess what's going on / why the result isn't what it should be.
Analogous idea: "if my render path doesn't exist, just render to a random folder without telling me you did it." -- you don't want that, it helps nothing.
-
Andrew Embury commented
Yes, please!