Creative Communities of the World Forums

The peer to peer support community for media production professionals.

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 pm

    Hi,

    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 pm

    Both 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 am

    You’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.aep

    Look at layer 3: “Point Control”.

    Thanks in advance.

  • Dan Ebberts

    February 14, 2008 at 1:25 am

    Hmmm… 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 am

    Well 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 am

    Ah, 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 am

    Thanks 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 :).

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy