Skip to main content

Operator

Introduction

Wave language provides various operators to perform calculations, logical judgments, comparisons, and bit operations between variables.

This document categorizes the main operators available in Wave and explains their operation methods, accompanied by examples.

Operators are divided into the following categories:

  • Arithmetic Operators
  • Comparison Operators
  • Logical Operators
  • Bitwise Operators
  • Assignment Operators
  • Other Special Operators

Arithmetic Operators

Arithmetic operators perform basic mathematical operations on numerical data.

OperatorDescriptionExample (a = 10, b = 3)
+Additiona + b13
-Subtractiona - b7
*Multiplicationa * b30
/Divisiona / b3 (Integer Division)
%Remainder Operationa % b1

Comparison Operators

Comparison operators return a bool value as a result of comparing two values.

OperatorDescriptionExample (a = 10, b = 3)
==Equala == bfalse
!=Not Equala != btrue
<Less Thana < bfalse
>Greater Thana > btrue
<=Less Than or Equal Toa <= 10true
>=Greater Than or Equal Toa >= btrue

Logical Operators

Logical operators handle combinations of true/false values for bool values.

OperatorNameDescriptionExample
&&Logical ANDOnly true if both values are truetrue && falsefalse
`\Logical ORtrue if at least one is true`true \
!Logical NOTInvert true to false, false to true!truefalse

Bitwise Operators

Bitwise operators manipulate integer type data at the bit level.

OperatorNameDescriptionExample
&Bitwise AND1 if both bits are 1a & b2
`\Bitwise OR1 if at least one bit is 1b7`
^Bitwise XOR1 if the bits are differenta ^ b5
~Bitwise NOTInvert bits~a-7
<<Left ShiftMove bits to the lefta << 112
>>Right ShiftMove bits to the righta >> 13

Assignment Operators

Used to store a value in a variable. In most cases, they can be combined with arithmetic operators for shorthand notation.

OperatorDescriptionExample (a = 5)
=Basic Assignmenta = 10
+=Addition Assignmenta += 27
-=Subtraction Assignmenta -= 14
*=Multiplication Assignmenta *= 315
/=Division Assignmenta /= 51
%=Remainder Assignmenta %= 41

Other Special Operators

Wave also provides operators with unique or special meanings as follows.

OperatorNameDescriptionExample
??Null Coalescing OperatorUses the right value if the left value is nulla ?? bif a is null, then b
?:Conditional Operator (Ternary Operator)Selects a value based on a conditioncondition ? true value : false value
inInclusion CheckCheck if a value is included in a collection"a" in list
isType Comparison OperatorCheck the type of a valuex is i32
!&NANDLogical NAND OperationAdvanced Logical Operation
`!\NORLogical NOR OperationAdvanced Logical Operation
!^XNORLogical XNOR OperationAdvanced Logical Operation

Summary

Wave provides a variety of operators ranging from mathematical operations to logical decisions, bit manipulation, and conditional branching. These operators are essential tools for interacting with variables, constructing conditions, and managing complex computations or flow control.

The precedence and associativity of each operator will be covered later in the "Precedence and Evaluation Order" section.