NIm Provides various operators.

• Relational Operators
• Logical Operators
• Athematic Operators

## Nim Arthematic Operators

Arithmetic operators are used to do operations such as add, division, subtraction, and division multiplication.

• addition (+) - Returns Integer
• subtraction(-) - returns Integer
• Multiplication(*) - Returns Integer
• Division (`/`) - Returns floating
• Division(division) - Returns Integer by ignoring fractional parts
• Modulus (mod)
OperatorTitleDescriptionExample
-Subtractionsubtraction of two or more operandsq-p=10
*Multiplicationmultiplication of two or more operandsp*q=600
/Divideresults quotient after the division of valuesq/p=1.5
DivInteger DivisionReturn the remainder after the division of valuesq div p=5
modModulusReturn the remainder after the division of valuesq mod p=10

Here is an arithmetic operator example

``````let
m = 17
n = 5

echo m + n
echo  m - n
echo  m * n
echo  m / n
echo m div n
echo m mod n
``````

Output:

``````22
12
85
3.4
3
2
``````

## Nim Relational Operators

Relational operators are used to compare the two operands and return a bool value.

ParameterNumber SymbolDescription
Equal`==`Both operands are equal or not,return boolean value
Not Equal`!=`Both operands are equal or not,return boolean value
Less Than`<`Used in One value is less than other Comparison
Greater Than`>`Used in One value is greater than other Comparison
Less Than Equal`<=`Used in One value is less than or equal to other comparisons
Greater Than or Equal`>=`Used in One value is greater than or equal other comparisons

Relational operator example

``````let opearnd1 = 10;
let operand2 = 20;
## Comparision Operators example
opearnd1 > operand2;  ## false
operand1 < operand2;  ## true
operand1 >= operand2;  ## false
operand1 <= operand2;  ## true
operand1 == operand2;  ## false
operand1 != operand2;  ## true
operand1 < operand2;  ## true
``````

## Nim Logical Operators

Logical operators are applies two operands and return a boolean value always. It is used to evaluate expression truthness.

It supports three operators in operators Logic And operator( `and` Logic OR operator( `or` Logic Not operator( `not`) Logic XOR operator( `not`)

|Parameter | Symbol |Description |:——–| ————— | |Logical AND| `and` |Both operands are true, return true, else false| |Logical OR|` or`|Both or One of the operands is true, return true, else false| |Logical NOT|`Not`|Returns reverse of Operand value. return true, else false| |Logical XOR |`xor`|Returns true, if one operand is true, other operation is false|

## NIM Logical Operators Examples

This is an example of a logical operator with code.

``````let opearnd1 = true;
let operand2 = false;
echo operand1 and operand2;
echo operand1 and true;
echo operand1 or true;
echo operand2 or false;

echo not operand1
echo not operand2
echo operand1 xor operand2
``````

Output

``````false
true
true
true
false
true
true
``````

## Nim Operators

• `shl operator`: Bit shift left

Here is an example

``````echo(100'i8  shl 1)  # -56
echo(100'i16 shl 1)  # 200
echo(100'i32 shl 1)  # 200
echo(100'i64 shl 1)  # 200
``````
• `shr operator`: Bit shift right

Here is an example

``````echo(-100'i8  shr 1)  # -50
echo(-100'i16 shr 1)  # -50
echo(-100'i32 shr 1)  # -50
echo(-100'i64 shr 1)  # -50
``````

`addr` operators return the `l-value` of a variable. `l-value` contains the location or value of the location.
``````var test = "test"