Mathematics

Source: Internet
Author: User

Small mathematics is not good.

Now, every time I see the method in the Math object, a white light will flash in my mind: What is this method?

It seems that ceil, floor, random, and round have been used in the past.

Floor (), minimum value

Ceil (), maximum value

Round (), returns the nearest value. When the value is exactly half (0.5), the maximum value is obtained.

Random (), needless to say, the range is 0 to 1 decimal places

Today, Math. abs () is used to obtain the absolute value.

Never used

Max (,) and min (,) are two big and small values after comparison.

All types in js are weak data types. That is to say, no matter what type is declared with var, the specific type depends on the value you pay for it.
Sometimes, for the sake of logical judgment, numbers and Boolean operations are used directly.

For example:

Specified usel. prototype = {glue: false, var totalMoved = this. vertical? (This. dy % this. myDivHeight)/this. myDivHeight * 100) *-1: (this. dx % this. myDivWidth)/this. myDivWidth * 100) *-1; // get a percentage of movement. touchMove: function (e) {if (! This. okToMove) {oldStateOkToMove = this. okToMove; this. okToMove = this. glue? Math. abs (totalMoved)> this. glue & Math. abs (totalMoved) <(100-this. glue): true; if (this. okToMove &&! OldStateOkToMove) {$. trigger (this, "movestart", [this. el]) ;}}

Tested:

It can be seen that when -- is executed, glue is still 0. After execution, glue is changed to-1.

If JavaScript does not understand anything, you can test it on the console! This is one of the secrets of learning.

In the previous example, there is a very long sentence:

Var totalMoved = this. vertical? (This. dy % this. myDivHeight)/this. myDivHeight * 100) *-1: (this. dx % this. myDivWidth)/this. myDivWidth * 100) *-1;

Note that the motion distance is taken as a percentage and the operator % is used.

% Returns the remainder (reserved integer) * = 5% 2 X = 1

This is the only arithmetic operator except addition, subtraction, multiplication, division, and so on.

In addition, the three-object operator is long and must be clear? The first is the condition, and the question mark is followed by the true and false values respectively.

Mathematics

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.