Jump to content
Search Community

roundProps overflow error?

CraptainRob test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hey there. I just had this little gem pop up and I'm wondering if this is expected behavior. If you tween to a very large value and use roundProps, it seems that the value eventually goes negative. Removing roundProps resolves this behavior. Note that manually rounding using Math.round does not do this.

var obj = {
    setValue: function (value) {
        console.debug(value);},
    getValue: function () {return 0;}
}

TweenLite.fromTo(obj, 5, {setValue: 0}, {setValue: 3750000000, roundProps: "setValue"});
Link to comment
Share on other sites

Very interesting. It looks like browsers don't handle the bitwise operator shortcut for rounding properly in cases like that (huge numbers). Furthermore, according to my tests, browsers have now optimized the Math.round() method such that there's no need to use the bitwise operator for speeding things up anyway (previously the bitwise trick was about 4x faster), so in the next update of GSAP I'll change to simply using Math.round(). If you need an update version ASAP, let me know and I can send you a preview. Thanks for pointing this out.

  • Like 2
Link to comment
Share on other sites

Hmm you're right it's not exactly expected, but hopefully it makes sense why it happened in the scheme of things:

In Javascript the Number type is a 64-bit floating point, which has a max value that your value isn't even close to approaching yet. A 32-bit integer however has a max about 1600000000 less than your value.

GSAP, in order to eek maximum performance out of every render frame, uses a bitwise OR 0 to round values instead of Math.round (according to Jack's testing, it's 4x faster). Bitwise operations function on 32-bit integers which is why you're seeing an overflow.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...