Erlang – Operators

Erlang Operators

Here we will discuss Operators in Erlang. An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.

Erlang has the following type of operators −

  • Arithmetic operators
  • Relational operators
  • Logical operators
  • Bitwise operators

Arithmetic Operators

Erlang language supports the normal Arithmetic operators as any the language. Following are the Arithmetic operators available in Erlang.

Show Examples

OperatorDescriptionExample
+Addition of two operands1 + 2 will give 3
Subtracts second operand from the first1 – 2 will give -1
*Multiplication of both operands2 * 2 will give 4
/Division of numerator by denominator2 / 2 will give 1
remRemainder of dividing the first number by the second3 rem 2 will give 1
divThe div component will perform the division and return the integer component.3 div 2 will give 1

Relational Operators

The Relational Operators allow the comparison of objects. Following are the relational operators available in Erlang.

Show Examples

OperatorDescriptionExample
==Tests the equality between two objects2 = 2 will give true
/=Tests the difference between two objects3 /= 2 will give true
<Checks to see if the left object is less than the right operand.2 < 3 will give true
=<Checks to see if the left object is less than or equal to the right operand.2 =<3 will give true
>Checks to see if the left object is greater than the right operand.3 > 2 will give true
>=Checks to see if the left object is greater than or equal to the right operand.3 >= 2 will give true

Logical Operators

These Logical Operators are used to evaluate Boolean expressions. Following are the logical operators available in Erlang.

Show Examples

OperatorDescriptionExample
orThis is the logical “or” operatortrue or true will give true
andThis is the logical “and” operatorTrue and false will give false
notThis is the logical “not” operatornot false will give true
xorThis is the logical exclusive “xor” operatorTrue xor false will give true

Bitwise Operators

Erlang provides four bitwise operators. Following are the bitwise operators available in Erlang.

Show Examples

Sr.No.Operator & Description
1band
This is the bitwise “and” operator
2bor
This is the bitwise “or” operator
3bxor
This is the bitwise “xor” or Exclusive or operator
4not
This is the bitwise negation operator

Following is the truth table showcasing these operators −

pqp & qp | qp ^ q
00000
01011
11110
10011

Operator Precedence

The following table shows the Operator Precedence for the Erlang operators in order of descending priority together with their associativity. Operator precedence and associativity are used to determine the evaluation order in un-parenthesized expressions.

OperatorsAssociativity
:
#
bnot,not
/,*,div,rem,band,andLeft associative
+,-,bor,bxor,or,xorLeft associative
==,/=,=<,<,>=,>

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply