标签:des style blog http color strong
Expr1 op Expr2
1> 1 == 1.
true
| op | Description |
| == | 等于 |
| /= | 不等于 |
| =< | 小于或等于 |
| < | 小于 |
| >= | 大于或等于 |
| > | 大于 |
| =:= | 恒等于 |
| =/= | 恒不等于 |
2> 1 == 1.0.true3> 1 =:= 1.0.false
number < atom < reference < fun < port < pid < tuple < list < bit string
op Expr Expr1 op Expr2
4> + 1.
1
5> 1 + 1.
2
| op | Description | Argument type |
| + | 一元 + | number |
| - | 一元 - | number |
| + | 加法 | number |
| - |
减法
|
number |
| * |
乘法
|
number |
| / | 浮点除法 | number |
| div |
整数除法
|
integer
|
| bnot | 一元 not 位运算 | integer |
| rem | 整数求余 | integer |
| band | 与运算 | integer |
| bor | 或运算 | integer |
| bxor | 异或运算 | integer |
| bsl | 左移运算 | integer |
| bsr | 右移运算 | integer |
例子如下:
6> +1.
1
7> -1.
-1
8> 1+1.
2
9> 4/2.
2.0
10> 5 div 2.
2
11> 5 rem 2.
1
12> 2#10 band 2#01.
0
13> 2#10 bor 2#01.
3
14> 8 bsr 1.
4
15> 8 bsl 1.
16
op Expr Expr1 op Expr2
| op | Description |
| not | 一元逻辑非 |
| and | 逻辑与 |
| or | 逻辑或 |
| xor | 逻辑异或 |
16> not true.
false
17> true and false.
false
18> true xor false.
true
Expr1 orelse Expr2 Expr1 andalso Expr2
什么是短路运算?
例子:
Expr1 and Expr2
Expr1 andalso Expr2
对于and运算,如果Expr1为假,还会继续执行Expr2,然后再判定表达式为假;而andalso运算,当Expr1为假就判定表达式为假,不再执行Expr2,所以这里andalso效率比较高。
简单谈谈Erlang的几种运算符,布布扣,bubuko.com
标签:des style blog http color strong
原文地址:http://blog.csdn.net/mycwq/article/details/37813635