- Erlang Tutorial
- Erlang - Home
- Erlang - Overview
- Erlang - Environment
- Erlang - Basic Syntax
- Erlang - Shell
- Erlang - Data Types
- Erlang - Variables
- Erlang - Operators
- Erlang - Loops
- Erlang - Decision Making
- Erlang - Functions
- Erlang - Modules
- Erlang - Recursion
- Erlang - Numbers
- Erlang - Strings
- Erlang - Lists
- Erlang - File I/O
- Erlang - Atoms
- Erlang - Maps
- Erlang - Tuples
- Erlang - Records
- Erlang - Exceptions
- Erlang - Macros
- Erlang - Header Files
- Erlang - Preprocessors
- Erlang - Pattern Matching
- Erlang - Guards
- Erlang - BIFS
- Erlang - Binaries
- Erlang - Funs
- Erlang - Processes
- Erlang - Emails
- Erlang - Databases
- Erlang - Ports
- Erlang - Distributed Programming
- Erlang - OTP
- Erlang - Concurrency
- Erlang - Performance
- Erlang - Drivers
- Erlang - Web Programming
- Erlang Useful Resources
- Erlang - Quick Guide
- Erlang - Useful Resources
- Erlang - Discussion
Erlang - Arithmetic Operators
Following are the Arithmetic operators available in Erlang.
Operator | Description | Example |
---|---|---|
+ | Addition of two operands | 1 + 2 will give 3 |
− | Subtracts second operand from the first | 1 - 2 will give -1 |
* | Multiplication of both operands | 2 * 2 will give 4 |
/ | Division of numerator by denominator | 2 / 2 will give 1 |
rem | Remainder of dividing the first number by the second | 3 rem 2 will give 1 |
div | The div component will perform the division and return the integer component. | 3 div 2 will give 1 |
The following code snippet shows how the various operators can be used.
Example
-module(helloworld). -export([start/0]). start() -> X = 40, Y = 50, Res1 = X + Y, Res2 = X - Y, Res3 = X * Y, Res4 = X / Y, Res5 = X div Y, Res6 = X rem Y, io:fwrite("~w~n",[Res1]), io:fwrite("~w~n",[Res2]), io:fwrite("~w~n",[Res3]), io:fwrite("~w~n",[Res4]), io:fwrite("~w~n",[Res5]), io:fwrite("~w~n",[Res6]).
The output of the above program will be −
Output
90 -10 2000 0.8 0 40
erlang_operators.htm
Advertisements