Swift Learning (one): Custom operator operator

Source: Internet
Author: User
Tags bitwise pow

Custom operators can contain only these characters:

/=-+ *% < >! & | ^. ~

Operator Location:

The predecessor operator    prefix the intermediate operator    infix the post operator    Postfix

Operator additional configuration

binding associativity desirable range of values left,right and none priority precedence desirable value range0~255system built-in operator combined with properties and priority exponentiation (no combination, priority)<<bitwise Left SHIFT (Bitwise)>>Bitwise Right SHIFT (Bitwise shift) multiplication correlation (left-associative, priority-level)*Multiply/except%Seeking Redundancy&*multiplication, ignoring overflow (Multiply, ignoring overflow)&/Division, ignoring overflow (Divide, ignoring overflow)&%redundancy, ignoring overflow (remainder, ignoring overflow)&bit-to (Bitwise and) plus subtraction (left-associative, priority-only)+Plus-minus&+Add with overflow&-Subtract with overflow|Bitwise or (Bitwise or)^Bitwise XOR (Bitwise XOR) Range (no combination, priority135): Semi-closed domain half-closed Range ... Full-closed Value Closed range type conversion (no combination, priority the) istype checks (type check) astype conversions (type cast)<=less than or equal>Greater than>=greater than or equal==equals!=Unequal===constant equals!==not identical~=Pattern matching (pattern match) Hop (conjunctive) (left-associative, priority -)&&logical AND (Logical and) disjunction (disjunctive) (left associative, priority the)||logical OR (Logical or) ternary condition (ternary Conditional) (right-associative, priority -)?: Ternary conditional ternary conditional Assignment (Assignment) (right-associative, priority -)=Assign Value (Assign)*=Multiply and assign/=Divide and assign%=Remainder and assign+=Add and assign-=Subtract and assign<<=Left bit shift and assign=Right bit shift and assign&=Bitwise and and assign^=Bitwise XOR and assign|=Bitwise OR and assign&&=Logical and and assign|| = Logical OR and assign

Example

//Front: Returns 2 of the n-th squarePrefixoperator^{}prefix func^ (varvector:double)Double {returnPow2, Vector)} println (^5)//32.0//Back : Returns 2-Time SquarePostfixoperator^{}postfix func^ (varVector:int)Int {returnVector *Vector}println (5^)// -//Middle: Calculates N's M-time, left-associative, priority 255Infixoperator^^ {associativity Left precedence255}func^^ (left:double, right:double)Double {returnPow (left, right)}println (2^^Ten-2^^3)//1024-8 = 1016

Swift Learning (one): Custom operator operator

Related Article

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.