Activity › Forums › Adobe After Effects Expressions › Limitations with Math.pow?
-
Limitations with Math.pow?
Posted by Allen Ellis on February 13, 2008 at 7:55 pmHi,
Whenever I try to use decimals or fractions for my exponent in Math.pow I get this error: Invalid numeric result (divide by zero?)
Math.pow(2,2.5), or Math.pow(2,1/3) both yield this error.
Is there a way for me to do this?
Thanks.
Allen Ellis replied 18 years, 2 months ago 2 Members · 6 Replies -
6 Replies
-
Dan Ebberts
February 13, 2008 at 9:35 pmBoth of those work fine for me when applied to a slider. What does the rest of your expression look like?
Dan
-
Allen Ellis
February 14, 2008 at 1:10 amYou’re right – it does.
The expression is applied to a point control. Here is the code:
x = this_comp.layer(“X”).effect(“X”).param(“Slider”);
y = Math.pow(x,3); // y = x^3[x,y]
It complains about the error on the last line, not line 2.
Here is the project file:
https://www.allenellis.com/public/Graph.aepLook at layer 3: “Point Control”.
Thanks in advance.
-
Dan Ebberts
February 14, 2008 at 1:25 amHmmm… that’s strange. I don’t get any expression errors when I open the project, and it renders fine. I notice that it’s a 5.5.1 project, so I’m wondering if it’s something that got fixed between 5.5 and 7.0 (the oldest version I have installed right now).
Maybe somebody can try it in 5.5.
Dan
-
Allen Ellis
February 14, 2008 at 1:48 amWell that project opens fine for me, too – I get the error when I change layer 3’s expression to be
y = Math.pow(x,2.5);
Or some other decimal/fraction number.
Sorry that I forgot to mention that. I didn’t want to submit a project with errors because I assumed it wouldn’t show the error that way.
-
Dan Ebberts
February 14, 2008 at 3:32 amAh, OK – here’s the deal. When you feed Math.pow() a negative number for x and a non-integer value for y, it tries to generate an imaginary or complex number, and the actual result you get is NaN. That’s what’s causing AE to throw the error. So – you’ll need to do something like this to get the curve you’re after:
x = this_comp.layer(“X”).effect(“X”).param(“Slider”);
if (x < 0){ y = -Math.pow(-x,2.5); }else{ y = Math.pow(x,2.5); } [x,y] Dan -
Allen Ellis
February 14, 2008 at 4:34 amThanks so much – that’s exactly what I needed.
I’m running into other similar issues now but they’re more minor and I think I’ll know how to deal with them now. Thanks again :).
Reply to this Discussion! Login or Sign Up