ECMASCRIPT5 Study Notes-11th chapter

Source: Internet
Author: User
Tags bitwise integer division

11. Expressions

11.1 Primary Value expression syntax: primaryexpression:this; executing thisbinding for the current execution environment

Identifier; Performs an identifier lookup that follows an identifier resolution. The result of an identifier execution is always a value of type Reference.

Literal;

arrayliteral; a sequence of 0 or more expressions, each of which represents an array element and is enclosed in square brackets.

When a comma in the list of elements is not assignmentexpression precedence (for example, a comma precedes another comma). ), the missing array element will still contribute to the length of the group and increase the index value of subsequent elements. The omitted array element is undefined. If the element is omitted at the end of the array, the element does not contribute to the array length.

Objectliteral (expression): Object initialization is an expression that describes the initialization process of an object in a direct amount. It is a list of 0 or more pairs of property name/association values enclosed in curly braces, and the value does not need to be a direct amount, and each time the object initialization is executed, they are executed once.

11.4.61 $ +-Operator

The unary +-operator converts its operand to a type

    1. Enables expr to interpret the result of executing unaryexpression.
    2. Returns Tonumber (GetValue (expr)).

11.4.8 bitwise non-operator ~unaryexpression

    1. Enables expr to interpret the result of executing unaryexpression.
    2. Make OldValue a ToInt32 (GetValue (expr)).
    3. Returns the result of OldValue bitwise inversion. The result is a 32-bit signed integer.

11.4.9 logical non-operator! Unaryexpression

    1. Enables expr to interpret the result of executing unaryexpression.
    2. Make OldValue a ToBoolean (GetValue (expr)).
    3. Returns False if OldValue is true.
    4. Returns True.

11.5 Multiplication Operators

Grammar: multiplicativeexpression:unaryexpression; multiplicativeexpression * unaryexpression; MultiplicativeExpression/ Unaryexpression; Multiplicativeexpression% Unaryexpression

    1. Leaves left to interpret the result of executing multiplicativeexpression.
    2. Make Leftvalue the GetValue (left).
    3. Let right explain the result of executing unaryexpression.
    4. Make Rightvalue the GetValue (right).
    5. Make Leftnum a Tonumber (leftvalue).
    6. Make Rightnum a Tonumber (rightvalue).
    7. Returns a specific operator (*,/, or%) Results that act on Leftnum and Rightnum

11.5.1 using the * operator

The * operator represents multiplication and produces the product of the operand. The multiplication operation satisfies the commutative law. Because of the accuracy problem, multiplication does not always satisfy the binding law.

The multiplication of floating-point numbers follows the IEEE 7,542-binary double-precision amplitude floating-point algorithm rule:

    • If one of the two operands is Nan, the result is Nan.
    • If the sign of two operands is the same, the result is positive, if the difference is negative.
    • Infinity is 0 times the result is Nan.
    • Infinity is infinitely large by the infinite Mahayana result. The symbols are determined according to the rules previously stated.
    • Infinity is a non-0 value that has a poor multiply result is an infinity with a positive sign. The symbols are still determined according to the rules previously stated.
    • In other cases, neither infinity nor Nan participates in the operation, and the results are calculated according to the IEEE 754 round-to-nearest pattern to the nearest number of energy representations. If the value is too large to be represented, the result is the corresponding positive or negative infinity. If the value is too small to be represented, the result is the corresponding positive or negative zero. ECMAScript requires support for progressive underflow as specified by IEEE 754.

11.5.2 using/Operator

The/operator represents the division that produces the quotient of the operand. The left operand is the divisor, and the right operand is the divisor. ECMAScript does not support integer division. The operands and results of all division operations are double-precision floating-point numbers. The division of floating-point numbers follows the IEEE 7,542 binary double-precision amplitude floating-point algorithm rule:

    • If one of the two operands is Nan, the result is Nan.
    • If the sign of two operands is the same, the result is positive, if the difference is negative.
    • Infinity is 0 apart from the result is Nan.
    • Infinity is infinitely large except that the result is Nan.
    • Infinity is 0 apart from the result is infinity. The symbols are determined according to the rules previously stated.
    • Infinity is not 0 has a poor value except that the result is an infinity with a positive sign. The symbols are determined according to the rules previously stated.
    • There are poor non-0 values that are infinitely large except that the result is zero. The symbols are determined according to the rules previously stated.
    • 0 are 0 apart from the result is Nan; 0 by the other has a poor number except that the result is zero, the symbol is determined according to the rules previously stated.
    • There is a poor non-0 value by 0 except that the result is an infinity with a positive sign . The symbols are determined according to the rules previously stated.
    • In other cases, neither infinity nor Nan participates in the operation, and the results are calculated according to the IEEE 754 round-to-nearest pattern to the nearest number of energy representations. If the value is too large to be represented, the result is the corresponding positive or negative infinity. If the value is too small to be represented, the result is the corresponding positive or negative zero. ECMAScript requires support for progressive underflow under IEEE 754

11.5.3 using the% operator

The% operator produces the remainder of its operator in division. The left operand is the divisor, and the right operand is the divisor.

In C and C + +, the remainder operator only accepts integers as operands, and in ECMAScript, it also accepts floating-point operands .

The remainder operation of floating-point numbers using the% operator is not exactly the same as the "remainder" Operation defined by IEEE 754. the IEEE 754 "remainder" operation computes the remainder of the neighbor-rounding method, rather than the end-of-ending division, so that its behavior is inconsistent with the usual meaning of the integer remainder operator behavior. The ECMAScript language defines a floating-point operation that is consistent with the Java fetch operator ; You can refer to the function fmod in the C library.

The ECMAScript floating-point method follows the IEEE 7,542 binary double-precision amplitude floating-point algorithm rule:

    • If one of the two operands is Nan, the result is Nan.
    • The sign of the result equals dividend.
    • If the divisor is infinite or the divisor is zero, or both, the result is Nan.
    • If the divisor is poor and the divisor is infinitely large, the result is dividend.
    • If the divisor is zero and the divisor is not 0 and is poor, the result is the same as the divisor.
    • In other cases, neither 0, infinity, or Nan participate in the operation, from the divisor N and divisor d to get floating-point number remainder R is defined in mathematical relation r = n− (DXQ) , where Q is an integer, negative when n/d is negative, positive at n/d, It should be as large as possible on the premise of not exceeding the quotient of N and D. The results are calculated according to the IEEE 754 round-to-nearest pattern to the nearest possible representation of the number

11.6 addition Operation Hair

11.6.1 plus operator:

The resulting additiveexpression:additiveexpression + multiplicativeexpression is performed as follows:

    1. The result of Lref to explain the execution of Additiveexpression.
    2. Make Lval a GetValue (lref).
    3. The result of Rref to explain the execution of Multiplicativeexpression.
    4. Make Rval a GetValue (rref).
    5. Make Lprim a toprimitive (lval).
    6. Make Rprim a toprimitive (rval).
    7. If Type (Lprim) is string or type (Rprim) is string: Returns a string that is concatenated by ToString (Lprim) and ToString (Rprim)
    8. Returns the result of the addition operation acting on Tonumber (Lprim) and Tonumber (Rprim)

The toprimitive call in steps 5 and 6 does not provide hint, except that all ECMAScript objects in addition to the date object treat the missing hint as number, and the Date object considers the absence of hint as hint as a string. The host object may treat the missing hint as something else.

11.6.2 minus operator

The resulting additiveexpression:additiveexpression-multiplicativeexpression is executed in the following procedure:

    1. The result of Lref to explain the execution of Additiveexpression.
    2. Make Lval a GetValue (lref).
    3. The result of Rref to explain the execution of Multiplicativeexpression.
    4. Make Rval a GetValue (rref).
    5. Make Lnum a Tonumber (lval).
    6. Make Rnum a Tonumber (rval).
    7. Returns the result of the subtraction operation acting on Tonumber (Lprim) and Tonumber (Rprim)

11.6.3 Addition for numbers

The + operator represents addition when acting on operands of two numeric types, resulting in the sum of two operands. -the operator represents subtraction, resulting in a difference of two digits.

Addition is an operation that satisfies the commutative law, but does not always satisfy the binding law.

The addition follows the IEEE 7,542 binary double-precision amplitude floating-point algorithm rule:

    • The infinite sum of the two positive and negative numbers is Nan.
    • Two the sum of the infinity with the same positive and negative sign is the infinity with the same positive or negative.
    • Infinity and the sum of the values are equal to infinity in the operand.
    • The sum of two negative 0 is-0.
    • two positive zeros, or two positive and negative 0 and +0.
    • 0 and non 0 have the sum of the values equal to the number of nonzero operands.
    • Two are equal in size, and non 0 with the opposite of the symbol has a sum of +0 of the poor value.
    • In other cases, neither infinity nor nan or 0 participate in the operation, and the operands are either of the same size, or the symbols are the same, and the results are calculated to take the closest possible representation of the IEEE 754 round-to-nearest pattern. If the value is too large to be represented, the result is the corresponding positive or negative infinity. If the value is too small to be represented, the result is the corresponding positive or negative zero. ECMAScript requires support for progressive underflow as specified by IEEE 754.

The-operator represents subtraction when acting on two numeric types, resulting in a difference of two operands. The left operand is the meiosis to the right is the meiosis. Given operands A and B, there is always a a–b generated with the same result as a + (-B).

11.7-bit arithmetic shift operator

Syntax: shiftexpression:additiveexpression, shiftexpression << additiveexpression; shiftexpression >> Additiveexpression, Shiftexpression >>> additiveexpression

11.7.1 left shift operator

Represents a bitwise left-shift operation that specifies the number of left operands to the right operand.

Production shiftexpression:shiftexpression << additiveexpression Follow the procedure below:

    1. The result of Lref to explain the execution of Shiftexpression.
    2. Make Lval a GetValue (lref).
    3. The result of Rref to explain the execution of Additiveexpression.
    4. Make Rval a GetValue (rref).
    5. Make Lnum a ToInt32 (lval).
    6. Make Rnum a ToUint32 (rval).
    7. Let Shiftcount calculate the last five bits of rnum with a mask, that is, the results of Rnum & 0x1F.
    8. Returns the result of Lnum left-shifted shiftcount bit. The result is a signed 32-bit integer.

11.7.2 with symbolic right shift operator

Production shiftexpression:shiftexpression >> additiveexpression Follow the procedure below:

    1. The result of Lref to explain the execution of Shiftexpression.
    2. Make Lval a GetValue (lref).
    3. The result of Rref to explain the execution of Additiveexpression.
    4. Make Rval a GetValue (rref).
    5. Make Lnum a ToInt32 (lval).
    6. Make Rnum a ToUint32 (rval).
    7. Let Shiftcount calculate the last five bits of rnum with a mask, that is, the results of Rnum & 0x1F.
    8. Returns the result of the right-shift shiftcount bit of the lnum symbol extension. The most significant bit is propagated. The result is a signed 32-bit integer.

11.7.3 Unsigned Right shift operator

Production shiftexpression:shiftexpression >>> additiveexpression Follow the procedure below:

    1. The result of Lref to explain the execution of Shiftexpression.
    2. Make Lval a GetValue (lref).
    3. The result of Rref to explain the execution of Additiveexpression.
    4. Make Rval a GetValue (rref).
    5. Make Lnum a ToUint32 (lval).
    6. Make Rnum a ToUint32 (rval).
    7. Let Shiftcount calculate the last five bits of rnum with a mask, that is, the results of Rnum & 0x1F.
    8. Returns the result of Lnum doing 0 padding to the right-shifted shiftcount bit. The missing bit is filled in 0. The result is an unsigned 32-bit integer.

ECMASCRIPT5 Study Notes-11th chapter

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.