The FXScript Reference

For Final Cut Pro created by Joe Maller

Abs

Abs(value)

Related Links:
kKeyOverlay

Additional Notes

Abs

Returns a positive integer for a given numerical value, essentially stripping the sign from the number. Abs(-4) returns 4

only returns integers

Abs returns only integers, in effect it works like Abs(Int(SomeValue)).

A workaround is to multiply your number before Abs-ing by a factor big enough to get the precision you need, and then dividing it again at the end vis:

mynum *= 1000
MyNewNum = Abs(mynum)
MyNewNum /= 1000


(BTW If you're unsure what *= and /= means, they're unary operators they mean multiply or divide the number on the left by the number on the right)

Floating Point Abs()

I found a subroutine in several of Apple's included effects called fabs(), presumably floating point abs:

on fabs (value _n)
    return (_n<0 ? -_n : _n);
end;


Before finding that I wrote my own version:

on absNoInt(value _num)
    return _num * sign(_num);
end


I never bothered to test which one was faster, it would depend on whether the ternary conditional (?:) operator was faster than the sign function.

So, with Abs(3.47)

Abs(3.47) would then become 4?

Rounds toward zero.

Abs will always return a positive integer based on your input. All values are rounded towards zero then returned as a positive number. So:

Abs(3.47) = 3
Abs(3.999999) = 3
Abs(-3.47) = 3

Speeeed

Hi Joe,

you can use my CommandSpeed-filter I gave you at the NAB to check which one is faster.

But I suspect that there won't be a big (noticable) difference between the two subroutins.

mine's faster :)

Hi Christoph, now that you've gone and called me out like that I guess I have no choice...

The performance is virutally identical, however my absNoInt() routine is just slightly faster than Apple's fabs(), by maybe 3-5%. Not a big deal, and they're both essentially instant.