comparison operator for Erlang
opdescription== equals/= not equal to =< less than equal to < less than >= greater than or equal > greater than =:= exact equals =/= exact difference equal to and exact equals:
If you want to compare two numbers, if two numbers are different types, such as float and int, then the = = Operation First converts two numbers to the same type. Example:
1> 1==1.0.
True
2> 1=:=1.0.
False
So the general recommendation is to use precision equals to compare
The size level of the comparison operator:
Number < Atom < Reference < fun < Port < pid < tuple < List < bit string
3> 1 > A.
False
Opdescriptionargument type+
number-
number+
number-
number*
number/floating-point number division, the result is a floating-point number numberbnot the unary not operator Integerdiv integer division, The result is an integer integerrem Yushu integerbandand Operation Integerboror Operation Integerbxorxor XOR operations INTEGERBSL left shift operation INTEGERBSR right shift operation Integer
logical operators
Opdescriptionnot logic Notand Logical Andor Logic Orxor logical XOR Atom True and false to represent logical "true" and "false"
In addition, the logical operators also include a OrElse and AndAlso
The original OR and and is operated without a "short-circuit operation", while the OrElse and AndAlso are operated with short-circuit operations.
Short Circuit Operation Example
Express1 and Express2
Express1 AndAlso Express2
If Express1 is false, and will continue to judge the Express2, and then the overall judgment is false, and andalso "short-circuit" operation, directly determine the entire expression is false, in terms of efficiency, AndAlso will be higher
Copy Code code as follows:
Op Description
= = equals
/= is not equal to
=< less than or equal
< less than
>= is greater than or equal to
> Greater than
=:= exactly equal to
=/= accurate is not equal to
Examples
Copy Code code as follows:
> 1==1.0.
True
> 1=:=1.0.
False
> 1 > A.
False
Note: The average language is less than or equal to "<=" and Erlang's "=<" writes