ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

# Tell if a value is positive or negative without IF statement.

FAQ   •   VIEW ALL
 Tell if a value is positive or negative without IF statement. on Mar 28, 2017 at 5:24:30 pm

I'm trying to determine if my value is positive or negative. Of course I could easily do an IF ELSE statement, but I need this expression to work on 400 layers simultaneously and IF ELSE has proven to slow things down immensely, so I try to find a way without using it.
In an ideal world I would get 1 if my value is positive and -1 if it's negative, but of course anything else like 1 and 0 or something like this would be great too.
I wrote this tiny expression, which works exactly like I want it to, but fails if the value is 0. Do anybody here know a better way?

`PosNeg = Math.abs(value)/value;`

http://www.schwarzgrau.com

 Re: Tell if a value is positive or negative without IF statement.on Mar 28, 2017 at 6:43:27 pm

`PosNeg = normalize(value);`

wouldn't give an error with 0, but would return NaN ('not a number').

maybe try and catch....
```try { PosNeg = Math.abs(value)/value; } catch (err) { 0; }```

Kevin Camp
Art Director
KCPQ, KZJO & KRCW

 Re: Tell if a value is positive or negative without IF statement.on Mar 29, 2017 at 1:31:54 pm

Perfect! Didn't know try and catch before. I guess I should read into it. Thank you a lot Kevin.

http://www.schwarzgrau.com

 Re: Tell if a value is positive or negative without IF statement.on Mar 28, 2017 at 7:05:17 pm

value >= 0

should give you 0 if negative, 1 if positive (or zero)

Dan