Operators
Precedence
Level | Operator(s) |
---|---|
1 | [] . |
2 | ~ - (unary) |
3 | * / // % |
4 | + - (subtract) |
5 | << >> |
6 | & |
7 | ^ |
8 | | |
9 | = != ~= > < >= <= in is is not |
10 | not |
11 | and |
12 | or |
Add
adds two numbers and returns their sum; or concatenates two strings or arrays; or returns the time after the given duration
Syntax:
x + y -> any
Examples:
2 + 3 = 5
2.5 + 3.5 = 6.0
"hello" + "world" = "helloworld"
[1, 2] + [3, 4] = [1, 2, 3, 4]
1 week + 1 day = 8 days
ParseTime("2020-01-01T00:00:00Z") + 1 week = ParseTime("2020-01-08T00:00:00Z")
ApproxEqual
returns true if values x and y are close to each other in absolute terms. Same as IsCloseTo
. For relative comparison of values close to zero, use IsRelativelyCloseTo
.
Syntax:
x ~= y -> bool
Examples:
0.1 + 0.2 ~= 0.3
(1 ~= 9) is false
(1e-20 ~= 9e-20) is true
ArrayIndex
returns the element in a at location i
Syntax:
a[i] -> any
Examples:
[1, 2][0] = 1
["a", "b"][-1] = "b"
ArraySlice
returns the elements in a between locations i and j
Syntax:
a[i:j] -> []any
Examples:
[1, 2][-1:] = [2]
["a", "b"][-99:99] = ["a", "b"]
BitwiseAnd
performs the bitwise AND operation on the integer inputs
Syntax:
x & y -> int
Examples:
5 & 3 = 1
127 & 63 = 63
BitwiseNot
performs the bitwise NOT operation on the (signed) integer input
Syntax:
~x -> int
Examples:
~3 = -4
~-7 = 6
BitwiseOr
performs the bitwise OR operation on the (signed) integer inputs
Syntax:
x | y -> int
Examples:
5 | 3 = 7
127 | 63 = 127
BitwiseXor
performs the bitwise XOR operation on the (signed) integer inputs
Syntax:
x ^ y -> int
Examples:
5 ^ 3 = 6
127 ^ 63 = 64
Divide
divides two numbers and returns their quotient
Syntax:
x / y -> number
Examples:
6 / 3 = 2
3 / 2 = 1.5
1.5 / 2 = 0.75
Equal
tests if two values are equal. Comparison to null returns null
Syntax:
x = y -> bool
Examples:
(3 = 3.0) is true
("foo" = "FOO") is false
(null = 5) is null
FloorDivide
divides two numbers and returns the whole part of their quotient
Syntax:
x // y -> number
Examples:
3 // 2 = 1
6.3 // 3.1 = 2
10.9 // 2 = 5
GreaterThan
tests if x is greater than y. Comparison to null returns null
Syntax:
x > y -> bool
Examples:
(4.0 > 3) is true
(2 > 2) is false
(1 week > 6 days) is true
GreaterThanEqual
tests if x is greater than or equal to y. Comparison to null returns null
Syntax:
x >= y -> bool
Examples:
(4.0 >= 3) is true
(2 >= 2) is true
(1 week >= 6 days) is true
In
returns whether x is in the array
Syntax:
x in a -> bool
Examples:
1 in [1, 2]
not (1 in [3, 4])
Is
tests if two values are equal and always returns true or false
Syntax:
x is y -> bool
Examples:
(3 is 3.0) = true
("foo" is "FOO") = false
(5 is null) = false
LeftShift
performs the bitwise left shift operation on the integer input
Syntax:
x << y -> int
Examples:
3 << 1 = 6
-6 << 2 = -24
LessThan
tests if x is less than y. Comparison to null returns null
Syntax:
x < y -> bool
Examples:
(3.0 < 4) is true
(2 < 2) is false
(6 days < 1 week) is true
LessThanEqual
tests if x is less than or equal to y. Comparison to null returns null
Syntax:
x <= y -> bool
Examples:
(3.0 <= 4) is true
(2 <= 2) is true
(6 days <= 1 week) is true
Mod
divides two numbers and returns the remainder
Syntax:
x % y -> number
Examples:
Mod(10, 5) = 0
Mod(3.5, 1.5) = 0.5
9 % 5 = 4
Multiply
multiplies two numbers and returns their product
Syntax:
x * y -> number
Examples:
2 * 3 = 6
2.5 * 3.5 = 8.75
RightShift
performs the bitwise right shift operation on the integer input
Syntax:
x >> y -> int
Examples:
6 >> 1 = 3
-24 >> 2 = -6
Subtract
substracts two numbers and returns their difference; or returns time turned back by duration
Syntax:
x - y -> any
Examples:
2 - 3 = -1
2.5 - 3.5 = -1.0
ParseTime("2020-01-08T00:00:00Z") - 1 week = ParseTime("2020-01-01T00:00:00Z")
UnaryMinus
negates a number
Syntax:
-x -> number
Examples:
-x + x = 0
-(-4) = 4
Unequal
tests if two values are unequal. Comparison to null returns null
Syntax:
x != y -> bool
Examples:
(3 != 3.0) is false
("foo" != "FOO") is true
(null != 5) is null