Skip navigation
amykwa
Currently Being Moderated

assigning float value to workAreaDuration

Jan 31, 2012 5:23 PM

So if I do the following in the Javascript Console window, a and b are the same value.

a = 1/3
Result: 0.33333333333333
b = a
Result: 0.33333333333333
b
Result: 0.33333333333333

 

However, if I do the following, item.workAreDuration isn't actually assigned the same value as a.

a = 1/3
Result: 0.33333333333333
item.workAreaDuration=a
Result: 0.33333333333333
item.workAreaDuration
Result: 0.33333334326744

 

Any ideas why this is happening?

 
Replies
  • Currently Being Moderated
    Feb 4, 2012 11:18 AM   in reply to amykwa

    Sounds like a possible bug, but I just tried this code in CS3, CS4, CS5 AND CS5.5 on OS X and got the same result in all of them. If it i a bug, it's been around for awhile.

     

    I also thought maybe it was a single frameDuration offset thing like when you use outPoint, but the difference didn't match up. Not sure what specifically is causing this, but maybe the algorithm for the timeline time is setup to prevent infinite number results and/or keeps the values within a compatible range based on the current timeline FPS, which would make sense given that there is no such thing as a half or fractional frame in video really.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 5, 2012 8:35 AM   in reply to amykwa

    I did some test and it seems the internal value that is stored is not a float but a 24bit signed integer for the decimal part of the number where each seconds is divided in 8388607 (or 0x7FFFFF) equal parts.

     

    So it is not a bug, but merely an internal precision thing that is still overkill.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 5, 2012 8:56 AM   in reply to amykwa

    If you need it, here is a function that will give the same result. It appear they are rounding the value you give to the 7th decimal.

     

    function workareaduration(val){

        var full = val - (val%1);

        var dec = Math.ceil(Math.round(val*10000000)*.0000001%1/(1/0x7fffff))*(1/0x7fff ff)

        return full + dec

    }

     

    workareaduration(0.33333333333333)

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 5, 2012 9:21 AM   in reply to chauffeurdevan

    Good to know chauffeurdevan. Figured they were doing something internal. This would also explain an issue I'm actually having on a script at the moment. I kept getting a returned timeline value outside the max length of the timeline. You inadvertedly answered my problem as well. Bonus.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 5, 2012 10:05 AM   in reply to David Torno

    For the value outside the timeline, you need to know that workAreaStart is relative to the displayStartTime. If the workAreaStart begin at the start of the comp, it will always be 0 independently of whether the comp start at 0:00:00:00 or 9:58:30:00.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 6, 2012 6:45 PM   in reply to amykwa

    I never used those. Not very sure they are working well.

     

    In fact you should multiply your frame number by the comp.frameDuration

     

    var frameNumber = 100;

    comp.workAreaDuration = comp.frameDuration * frameNumber;

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points