11 Replies Latest reply on Feb 7, 2012 10:52 AM by amykwa

# assigning float value to workAreaDuration

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
Result: 0.33333333333333
Result: 0.33333334326744
```

Any ideas why this is happening?

• ###### 1. Re: assigning float value to workAreaDuration

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.

• ###### 2. Re: assigning float value to workAreaDuration

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.

• ###### 3. Re: assigning float value to workAreaDuration

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.

var full = val - (val%1);

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

return full + dec

}

• ###### 4. Re: assigning float value to workAreaDuration

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.

• ###### 5. Re: assigning float value to workAreaDuration

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.

1 person found this helpful
• ###### 6. Re: assigning float value to workAreaDuration

That's good to know that workAreaStart is relative to displayStartTime.

As for being able to set workAreaDuration to a float value, the function above doesn't really solve the problem I'm having. The timeline I'm working with is in frames and I would like to be able to do this:

comp.workAreaDuration = currentFormatToTime("00100", 24)

but timeToCurrentFormat() returns 99 rather than 100 since the float value assigned is only accurate to the 7th decimal.

• ###### 7. Re: assigning float value to workAreaDuration

One thing I noticed is that I'm able to set comp.duration to a float value without the value changing, but comp.displayStartTime, comp.workAreaStart, and comp.workAreaDuration will change the float value.

• ###### 8. Re: assigning float value to workAreaDuration

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;

• ###### 9. Re: assigning float value to workAreaDuration

The functions currentFormatToTime() and timeToCurrentFormat() seem to work ok. I can assign the value from currentFormatToTime() to a variable and get the correct float value.

```a = currentFormatToTime("00100", 24)
```

The variable 'a' gets assigned 4.16666666666667 as I would expect.

But if I try assigning the value from currentFormatToTime() to comp.workAreaDuration, I get 4.16666650772095 instead.

```comp.workAreaDuration = currentFormatToTime("00100", 24)
```

Even the following doesn't set comp.workAreaDuration to 4.16666666666667.

```var frameNumber = 100;
```

So it boils down to that assigning something like 1/3 or 100/24 to an arbitrary variable vs assigning it to comp.workAreaDuration gives you different results.

```a = 100/24;
```
• ###### 10. Re: assigning float value to workAreaDuration

If you run this code, it hopefully explains better what the problem is. It looks like duration and workAreaStart get assigned the correct float value, but displayStartTime and workAreaDuration do not.

First in a new project, create a new composition (Composition->New Composition...).

Then run this code in the script editor.

```var a = 1/24;
var comp = app.project.item(1);
comp.displayStartTime = 1/24;
var b = 200/24;
comp.duration = 200/24;
var c = 1/24;
comp.workAreaStart = 1/24;
var d = 100/24;
"\n\nb=200/24\t\t\t"+b+"\nduration=200/24\t\t"+comp.duration+
"\n\nc=1/24\t\t\t"+c+"\nworkAreaStart=1/24\t\t"+comp.workAreaStart+
```
• ###### 11. Re: assigning float value to workAreaDuration

Ok, I think I might have figured out something that'll work for what I'm trying to do.