## LSL Wiki : Unary

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl338.us.archive.org

### Unary

Unary operators take one argument. In LSL these arguments are normally integers.

 Operator Type Meaning Return Value Effect variable++ Arithmetic post-increment variable variable is set to variable + 1 ++variable Arithmetic pre-increment variable + 1 variable is set to variable + 1 variable-- Arithmetic post-decrement variable variable is set to variable - 1 --variable Arithmetic pre-decrement variable - 1 variable is set to variable - 1 !variable Logical Logical NOT 1 if variable is 0, otherwise 0 None -variable Arithmetic Unary negation negative value of variable None ~variable Bitwise Bitwise NOT flips each bit of variable None

#### Examples:

```integer x = 5;
llSay(0, (string)(x++));
//Says "5" and x is set to 6```
```integer x = 5;
llSay(0, (string)(++x));
//Says "6" and x is set to 6```

Operators | Unary | Binary | Bitwise | Boolean | Equality | Assignment
It is said that j++ is slower than j = j + 1. I ran a test to see whether that was true:

Increment test: It took 129.376556 seconds to exec j = j + 1 10,000 times in a for loop.
Increment test: It took 153.302780 seconds to exec j++ 10,000 times in a for loop.

The math for that test works out to j = j + 1 being .002 seconds faster than j++. Personally I'm staying with ++.
-- HunsValen (2004-05-11 04:47:54)
That's 0.002 seconds I can't afford to waste!

This is interesting Huns, why not move this info up in to the page, or on to the speed-tweaks page?
-- WednesdayGrimm (2004-05-14 11:24:11)
Also note that you can combine assignment and binary operators, like other languages.
"j = j + 1;" can also be written as "j += 1;"
Technically, the "short-hand" version is faster - but tests have shown the difference to only be about 0.00007 seconds. :-)