Panther Search Documentation Tutorials Devlogs Downloads Source Code

Documentation > Panther Documentation > Operators

Operators

Panther
Documentation


  Operators are a set of operations that create an expression from one or more sub-expressions. Unless remarked otherwise, all operators support operator overloading and forwarding of fluid values. In addition, all operators are constexpr (unless they are overloaded, in which case it is overload specific).

Arithmetic Operators

Name Syntax Supported Builtin Types Example Remarks
Addition
a + b

integral

floating-point

vector of integral

vector of floating-point

1 + 2 // 3

Type of return is the type of arguments.

Integer overflowing is undefined behavior.

Wrapping Addition
a +% b

integral

vector of integral

1 +% (255 as UI8) // 0

Type of return is the type of arguments.

Integer overflowing is allowed (two's compliment).

Saturating Addition
a +| b

integral

vector of integral

1 +| (255 as UI8) // 255

Type of return is the type of arguments.

Subtraction
a - b

integral

floating-point

vector of integral

vector of floating-point

5 - 2 // 3

Type of return is the type of arguments.

Integer overflowing is undefined behavior.

Wrapping Subtraction
a -% b

integral

vector of integral

5 -% (6 as UI8) // 255

Type of return is the type of arguments.

Integer overflowing is allowed (two's compliment).

Saturating Subtraction
a -| b

integral

vector of integral

5 -| (6 as UI8) // 0

Type of return is the type of arguments.

Multiplication
a * b

integral

floating-point

vector of integral

vector of floating-point

5 * 2 // 10

Type of return is the type of arguments.

Integer overflowing is undefined behavior.

Wrapping Multiplication
a *% b

integral

vector of integral

32 *% (8 as UI8) // 0

Type of return is the type of arguments.

Integer overflowing is allowed (two's compliment).

Saturating Multiplication
a *| b

integral

vector of integral

32 *| (8 as UI8) // 255

Type of return is the type of arguments.

Division
a / b

integral

floating-point

vector of integral

vector of floating-point

7 / 3 // 2

Type of return is the type of arguments.

Integer overflowing is undefined behavior.

Division Remainder
a % b

integral

floating-point

vector of integral

vector of floating-point

7 % 3 // 1

Type of return is the type of arguments.

Integer overflowing is allowed (two's compliment).

Negate
-a

integral

floating-point

vector of integral

vector of floating-point

-12 // -12

Type of return is the type of argument.

Comparative Operators

Name Syntax Supported Builtin Types Example Remarks
Equal To
a == b any compatable types 12 == 10 // false
12 == 12 // true
12 == 14 // false

Type of return is Bool.

Not Equal To
a != b any compatable types 12 != 10 // false
12 != 12 // true
12 != 14 // false

Type of return is Bool.

Less Than
a < b any compatable types 12 < 10 // false
12 < 12 // false
12 < 14 // true

Type of return is Bool.

Less Than or Equal To
a <= b any compatable types 12 <= 10 // false
12 <= 12 // true
12 <= 14 // true

Type of return is Bool.

Greater Than
a > b any compatable types 12 > 10 // true
12 > 12 // false
12 > 14 // false

Type of return is Bool.

Greater Than or Equal To
a >= b any compatable types 12 >= 10 // true
12 >= 12 // true
12 >= 14 // false

Type of return is Bool.

Bitwise Operators

Name Syntax Supported Builtin Types Example Remarks
Bitwise And
a & b

integral

vector of integral

0b1010 & 0b0110 // 0b0010

Type of return is the type of arguments.

Bitwise Or
a | b

integral

vector of integral

0b1010 | 0b0110 // 0b1110

Type of return is the type of arguments.

Bitwise Xor
a ^ b

integral

vector of integral

0b1010 | 0b0110 // 0b1100

Type of return is the type of arguments.

Bit Shift Left
a << b

integral

vector of integral

0b0101 << 2 // 0b10100

Type of return is the type of LHS.

RHS must be ceil(log2(@numBits<{LHS}>())).

Saturating Bit Shift Left
a <<| b

integral

vector of integral

(0b11 as UI8) << 7 // 255

Type of return is the type of LHS.

RHS must be ceil(log2(@numBits<{LHS}>())).
This restriction most likely will change in the future,
but more consideration is required.

Bit Shift Right
a >> b

integral

vector of integral

0b11000 >> 2 // 0b110

Type of return is the type of LHS.

RHS must be ceil(log2(@numBits<{LHS}>())).

Bitwise Not
~a

integral

vector of integral

~(0b10101110 as UI8) // 0b01010001

Type of return is the type of argument.

Does not support fluid values

Pointer/Optional Operators

Name Syntax Supported Builtin Types Example Remarks
Address Of
&a

Any

var num: Int = 12;
const num_ptr: Int* = &num;
num_ptr.* // 12

Argument must be concrete.

Using on a const object returns a read-only pointer,
otherwise is a pointer.

Read-Only Address Of
&|a

Any

var num: Int = 12;
const num_ptr: Int*| = &|num;
num_ptr.* // 12

Argument must be concrete.

Dereference
a.*

Any pointer

var num: Int = 12;
const num_ptr: Int* = &num;
num_ptr.* // 12

Dereferencing a read-only pointer results in a
const value, otherwise the value is mutable.

Unwrap
a.?

Any optional

var opt_num: Int? = 12;
opt_num.? // 12

It is undefined behavior to unwrap an optional
that is null.

Boolean

Name Syntax Supported Builtin Types Example Remarks
Logical And
a && b

Bool

true && false // false

Type of return is Bool.

If LHS is false, don't evaluate RHS and return false.

Logical Or
a || b

Bool

true || false // false

Type of return is Bool.

If LHS is true, don't evaluate RHS and return true.

Boolean Not
!a

Bool

!true // false

Type of return is Bool.

Object Operators

  copy a(TODO)

  move a(TODO)

  forward a(TODO)

Type Conversion Operator

  a as b(TODO)

Accessor Operator

  a.b(TODO)

Composite Assignment Operators

  (TODO)

Operator Precedence

Precedence Operators
1 a.ba.*a.?
2 &a&|acopy amove aforward a-a!a~a
3 a as b
4 a * ba *% ba *| ba / ba % b
5 a + ba +% ba +| ba - ba -% ba -| b
6 a << ba <<| ba >> b
7 a & ba | ba ^ b
8 a == ba != ba < ba <= ba > ba >= b
9 a && b
10 a || b