English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Erlang Operators

An operator is a symbol that tells the compiler to perform a specific mathematical or logical operation.

Erlang has the following types of operators -
  • Arithmetic operators

  • Relational operators

  • Logical operators

  • Bitwise Operators

Arithmetic operators

The Erlang language supports normal arithmetic operators similar to those in other languages. The following are the arithmetic operators available in Erlang.

Arithmetic operator example

Operator Description Example
+ Two operands are added 1 + 2 = 3
The first operand is subtracted from the second operand 1 - 2 = -1
*Two operands are multiplied 2 * 2 = 4
/
By dividing the numerator by the denominator
2 / 2 = 1
rem
The remainder when the second number is divided by the first number
3 rem 2 = 1
div
The div component will perform division and return the integer part
3 div 2 = 1

Relational operators

Relational operators allow object comparison. The following are the relational operators available in Erlang.

Relational operator example

Operator Description Example
== Tests if two objects are equal 2 = 2 Results in true
/= Tests if two objects are not equal 3 /= 2 Results in true
< Tests if the left object is less than the right operand object 2 < 3 Results in true
<=Tests if the left object is less than or equal to the right operand object 2 <=3 Results in true
>Tests if the left object is greater than the right operand object 3 > 2 Results in true
>=Tests if the left object is greater than or equal to the right operand object 3 >= 2 Results in true

Logical operators

These logical operators are used to calculate boolean expressions. The following are the logical operators available in Erlang.

Logical operator example

Operator Description Example
or Logical "or" operator True or true results in true
andLogical "and" operator True AND false results in false
notLogical 'not' Operator NOT false results in true
xorLogical 'xor' Operator True XOR false results in false

Bitwise Operators

Erlang provides four bitwise operators. The following are the bitwise operators available in Erlang.

Bitwise Operator Examples

S.No. Operator & Description
1

band

Bitwise 'and' Operator

2

bor

Bitwise 'or' Operator

3

bxor

Bitwise 'xor' or Exclusive OR Operator

4

bnot

Bitwise NOT Operator
The following truth tables show these operators -
p q p & q p | q p ^ q
0 0 0 0 0
0 1 0 1 1
1 1 1 1 0
1 0 0 1 1

Operator Precedence

The following table shows the precedence of operators in Erlang, as well as their associated decreasing precedence order. Operator precedence is used to determine the order of calculation in expressions without parentheses.
Operators Association
:

#

bnot,not

/,*,div,rem,band,andLeft Association
+,-,bor,bxor,or,xorLeft Association
==,/=,=<,<,>=,>