• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

divide by 0?

Contributor ,
Dec 08, 2016 Dec 08, 2016

Copy link to clipboard

Copied

Hi, one of my expressions got disabled due to an "invalid numeric result (divide by 0?)" , but as far as i can see, i am not dividing by 0.

my code:

var f=timeToFrames(t = time + thisComp.displayStartTime, fps = 1.0 / thisComp.frameDuration, isDuration = false);

var c= thisComp.height;

var h=(c-1)/2;

var a= f-z*c;

var z=(f/c)-(1/10000000);

var s=4/(c-1);

var x=(-(h+1)+a)*s;

var y=(h-z)*s;

[x,y]

The super weird thing is, that when i change the "z" in var a to "3", the expression works, but when i replace the whole value of var z to "3", i get the same error. Shouldn't the two give the exact same result??

Thanks and kind regards,

TOPICS
Expressions

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Dec 08, 2016 Dec 08, 2016

i am not dividing by 0.

Sure you are:

var f=timeToFrames()

The result of time conversions like this can be zero and then you are also calculating the millionth fraction of something in var z. For all intents and purposes, there could be quantization and internal rounding errors. Your code seems awfully convoluted, anyway. Why not concatenate and consolidate the functions into a single formula? Even declaring the variables with var= is redundant in JavaScript and does nothing for you.

Mylenium

Votes

Translate

Translate
LEGEND ,
Dec 08, 2016 Dec 08, 2016

Copy link to clipboard

Copied

i am not dividing by 0.

Sure you are:

var f=timeToFrames()

The result of time conversions like this can be zero and then you are also calculating the millionth fraction of something in var z. For all intents and purposes, there could be quantization and internal rounding errors. Your code seems awfully convoluted, anyway. Why not concatenate and consolidate the functions into a single formula? Even declaring the variables with var= is redundant in JavaScript and does nothing for you.

Mylenium

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 09, 2016 Dec 09, 2016

Copy link to clipboard

Copied

It's probably because you use the z variable before assigning it a value.

var a= f-z*c;

var z=(f/c)-(1/10000000);

Xavier

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 09, 2016 Dec 09, 2016

Copy link to clipboard

Copied

LATEST

Hey, thank you guys, both your suggestions work fine, i am tagging Myleniums Answer as the correct one because he was first, but Thanks alot to you too, UQg!! I am really new to AE expressions and coding in general, but i am really interested and learning every day, also thanks to community members like you...:)

I already ran into the next problem in my project, i opened a new discussion and would very much appreciate you giving it a look, if you have time...thanks

Iteration Counter

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines