Erlang-operators
提供:Dev Guides
アーラン-オペレーター
演算子は、特定の数学的または論理的な操作を実行するようコンパイラーに指示する記号です。
Erlangには次のタイプの演算子があります-
- 算術演算子
- 関係演算子
- 論理演算子
- ビットごとの演算子
算術演算子
Erlang言語は、すべての言語として通常の算術演算子をサポートしています。 Erlangで使用できる算術演算子は次のとおりです。
リンク:/erlang/erlang_arithmatic_operators [例を表示]
| 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 |
関係演算子
関係演算子を使用すると、オブジェクトを比較できます。 Erlangで使用できる関係演算子は次のとおりです。
リンク:/erlang/erlang_relational_operators [例を表示]
| Operator | Description | Example |
|---|---|---|
| == | Tests the equality between two objects | 2 = 2 will give true |
| /= | Tests the difference between two objects | 3/= 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 |
論理演算子
これらの論理演算子は、ブール式を評価するために使用されます。 Erlangで使用できる論理演算子は次のとおりです。
リンク:/erlang/erlang_logical_operators [例を表示]
| Operator | Description | Example |
|---|---|---|
| or | This is the logical “or” operator | true or true will give true |
| and | This is the logical “and” operator | True and false will give false |
| not | This is the logical “not” operator | not false will give true |
| xor | This is the logical exclusive “xor” operator | True xor false will give true |
ビット演算子
Erlangは4つのビット演算子を提供します。 Erlangで使用できるビット演算子は次のとおりです。
リンク:/erlang/erlang_bitwise_operators [例を表示]
| Sr.No. | Operator & Description |
|---|---|
| 1 |
band これはビット単位の「and」演算子です |
| 2 |
bor これはビット単位の「or」演算子です |
| 3 |
bxor これはビット単位の「xor」または排他的論理和演算子です |
| 4 |
bnot これはビットごとの否定演算子です |
以下は、これらの演算子を示す真理値表です-
| 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 |
演算子の優先順位
次の表に、アーラン演算子の演算子の優先順位を、優先度の降順と結合性の順に示します。 演算子の優先順位と結合性を使用して、括弧なしの式の評価順序を決定します。
| Operators | Associativity |
|---|---|
| : | |
| # | |
| bnot,not | |
| /,*,div,rem,band,and | Left associative |
| PLUS,-,bor,bxor,or,xor | Left associative |
| ==,/=,=<,<,>=,> |