Erlang operators (comparison operators, numerical operators, shift operators, logical operators)

Source: Internet
Author: User
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

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

Erlang comparison Operators

OpDescription = equal to/= not equal to = <小于等于<小于> = Greater than or equal to> greater than =: = exact equals =/= exact 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 floating-point numberbnot unary not operator integerp integer division, the result is the integer integerrem to calculate the Yushu integerbandand operation the integerboror operation the integerbxorxor operation the integerbsl left shift operation
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

The Code is as follows:
Op Description
= Equal
/= Not equal
= <Less than or equal
<Less
> = Greater than or equal
> Greater
=: = Exact equals
= // = Exact not equal

Examples
The 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.