Erlang comparison Operators
OpDescription = equal to/= not equal to = <less than or equal to <less than> = greater than or equal to> greater than =: = exact equals =/= exact equals not equal to or exact equals:
To compare two numbers, if they are of different types, such as float and int, The = operation first converts the two numbers to the same type. Example:
1> 1 = 1.0.
True
2> 1 =: = 1.0.
False
Therefore, we recommend that you use exact equals to decomparison.
Comparison operator size level:
Number <atom <reference <fun <port <pid <tuple <list <bit string
3> 1>.
False
OpDescriptionArgument type +
Number-
Number +
Number-
Number *
Number/floating-point division. The result is the integer division of the floating-point numberbnot unary not operator integerdiv. The result is the integer integerrem. The result is the integer integerrem. The integerboror operation is the integer.
Logical operators
OpDescriptionnot mona1 logic notand logic andor logic orxor logic xor atom true and false indicate logical "true" and "false"
In addition, the logical operators include orelse and andalso
The original or and operations do not contain short-circuit operations, while orelse and andalso operations do not.
Example of short circuit operation
Express1 and Express2
Express1 andalso Express2
If Express1 is false, and will continue to judge Express2, then the overall determination is false, and andalso "Short Circuit" operation, directly determine the entire expression is false, in terms of efficiency, andalso will be higher
Copy codeThe Code is as follows: op Description
= Equal
/= Not equal
= <Less than or equal
<Less
> = Greater than or equal
> Greater
=: = Exact equals
= // = Exact not equal
ExamplesCopy codeThe Code is as follows:> 1 = 1.0.
True
> 1 =: = 1.0.
False
> 1>.
False
Note: Generally, the language is less than or equal to "<=" and erlang's "= <" is written in this way.