Erlang-arithmatic-operators
提供:Dev Guides
アーラン-算術演算子
Erlangで使用できる算術演算子は次のとおりです。
Operator | Description | Example |
---|---|---|
PLUS | Addition of two operands | 1 PLUS 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 |
次のコードスニペットは、さまざまな演算子の使用方法を示しています。
例
-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]).
上記のプログラムの出力は次のようになります-
出力
90
-10
2000
0.8
0
40