Operators

Unary Operators

Unary operators appear before the operand in Whistle and modifies it in a set way:

operator operand

For exampe -10 where - is the operator and 10 is the operand.

precedenceoperatoroperand typedescription
0-Signed NumberThe arithmetic negate operator negates the sign of the operand
0!BooleanThe logical not operator inverts the operand
0~IntegerThe bitwise not operator inverts the bits of the operand

Binary Operators

Binary operators appear between to operands:

operand operator operand

For exampe 5 - 10 where - is the operator, 5 and 10 is the operands.

Arithmetic Operators

precedenceoperandoperatoroperanddescription
1Number**NumberThe exponentiation operator calculates the left operands to the power of the right
2Number*NumberThe multiplication operator multiplies the operands
2Number/NumberThe division operator divides the operands
2Number%NumberThe modulo operator calculates the remainder operands
3Number+NumberThe addition operator adds the operands
3Number-NumberThe subtraction operator subtracts the operands

String Operators

precedenceoperandoperatoroperanddescription
3String+StringConcatinates the right operand to the left

Comparison Operators

precedenceoperandoperatoroperanddescription
5Any>=AnyIs the left operand greater than or equal to the right operand?
5Any>AnyIs the left operand greater than the right operand?
5Any<=AnyIs the left operand less than or equal to the right operand?
5Any<AnyIs the left operand less than the right operand?
6Any==AnyAre the operands equal?
6Any!=AnyAre the operands unequal?

Logical Operators

precedenceoperandoperatoroperanddescription
10Boolean&&BooleanAre both the operands true?
11Boolean||BooleanIs one of the operands true?

Bitwise Operators

precedenceoperandoperatoroperanddescription
4Integer<<IntegerThe bitwise left shift operator shifts the left operand in binary representation right operand number of bits to the left
4Integer>>IntegerThe bitwise left shift operator shifts the left operand in binary representation right operand number of bits to the right
7Integer&IntegerThe bitwise and operator returns a one in each bit position for which the corresponding bits of both operands are ones
8Integer^IntegerThe bitwise xor returns a zero in each bit position for which the corresponding bits are the same
9Integer|IntegerThe bitwise or returns a zero in each bit position for which the corresponding bits of both operands are zeros

Assignment Operators

precedenceoperandoperatoroperanddescription/equivalent
12Number**=Numberleft_operand = left_operand ** right_operand
13Number*=Numberleft_operand = left_operand * right_operand
13Number/=Numberleft_operand = left_operand / right_operand
13Number%=Numberleft_operand = left_operand % right_operand
14String+=Stringleft_operand = left_operand + right_operand
14Number+=Numberleft_operand = left_operand + right_operand
14Number-=Numberleft_operand = left_operand - right_operand
15Number>>=Numberleft_operand = left_operand >> right_operand
15Number<<=Numberleft_operand = left_operand << right_operand
16Number&=Numberleft_operand = left_operand & right_operand
17Number^=Numberleft_operand = left_operand ^ right_operand
18Number|=Numberleft_operand = left_operand | right_operand
19Boolean&&=Booleanleft_operand = left_operand && right_operand
20Boolean||=Booleanleft_operand = left_operand || right_operand
21Any=AnyAssigns the right value to the left

Conditional Operator

The conditional operator is the only operator which takes three operands:

operand if operand else operand

Where the first operand signifies the value if the second operand is true, otherwise the third operand is the value of the operation.