-
Notifications
You must be signed in to change notification settings - Fork 1
Operators
Liu Siwei edited this page Aug 20, 2017
·
4 revisions
- Addition
+
- Subtraction
-
- Multiplication
*
- Integer division
/
- Floating point number division
/.
- Remainder
%
- Power
**
a := 1 + 2 // a equals 3;
b := 10 - 2 // b equals 8;
c := 5 * 2 // c equals 10;
d := 9 / 5 // d equals 1;
e := 9 /. 5 // e equals 1.8;
f := 9 % 5 // f equals 4;
g := 2 ** 3 // g equals 8;
variable_name = expression;
a := 10 // a <- 10
b := a // b <- 10
c := a + 2 // c <- (10 + 2)
- Equal
==
- Not equal
!=
- Less than
<
- Less than or equal
<=
- Greater than
>
- Greater than or equal
>=
- Logical NOT
!
- Logical AND
&&
- Logical OR
||
Operator | Description | Example | In binary | Result | In binary |
---|---|---|---|---|---|
& | AND | 7 & 2 | 111 & 10 | 2 | 10 |
| | OR | 5 | 3 | 101 | 11 | 7 | 101 |
~ | NOT | ~5 | ~[60 0s]0101 | -6 | [60 1s]1010 |
^ | XOR | 5 ^ 3 | 101 ^ 11 | 6 | 110 |
<< | Zero fill left shift | 5 << 1 | 101 << 1 | 10 | 1010 |
>> | Signed right shift | -5 >> 1 | [60 1s]1011 >> 1 | -3 | [60 1s]1101 |
>>> | Zero fill right shift | 5 >>> 1 | 101 >>> 1 | 2 | 10 |
- Increment
++
- Decrement
--
a := 5
a++ // same as a = a + 1;
print( a ) // output 6
YJLO Script supports both pre and post increment/decrement.
i := 1
print(++i) // output 2
print(i) // output 2
print(i++) // output 2
print(i) // output 3
- Add and assign
+=
- Subtract and assign
-=
- Multiply and assign
*=
- Divide (integer) and assign
/=
- Divide (float) and assign
/.=
- Remainder and assign
%=
- Power and assign
**=
- Bitwise AND and assign
&=
- Bitwise OR and assign
|=
- Bitwise XOR and assign
^=
- Left shift and assign
<<=
- Right shift and assign
>>=
- Zero fill right shift and assign
>>>=
a := 5
a *= 2 // same as a = a * 2;
print( a ) // output 10
condition ? expr1 : expr2
If condition
is true, the operator returns the value of expr1
; otherwise, it returns the value of expr2
.
a := 2
b := a*2 > 5 ? a : 5 // a*2 > 5 is false => b = 5
print(b < 10 ? "A" : "B") // b < 10 is true => print "A"
// output A
Introduction
Langauge Guide
Libraries
- Utility
- ListUtil
- StringUtil
- Math
- Data Structure
- LinkedList
- Stack
- Heap
- HeapList
- HashMap
- HashSet
- Others
- UnitTest
- Tokenizer
Dev Reference
- Syntax Sugar