JavaScript reference types-built-in objects (Math object)

Source: Internet
Author: User
Tags natural logarithm root math square root

There are many JavaScript that do not have to instantiate the built-in objects, as they have been instantiated, as described earlier in object,array,string. Then there are two single built-in objects: Global and math. The global object can be said to be a special object because you cannot see his presence, and all global scope-defined properties and functions are properties of the global object.
Here's a discussion of the Math object the Math object provides much faster execution than other computational methods, and also provides properties and methods to assist in the completion of these calculations.
min () and Max ()This can be used to determine the maximum minimum value in a set of arrays, for example: Var Max=math.max (3,3,4,5,2,6,1,5), or the Apply () method if you are looking for the maximum or minimum value in the array, for example: var nums = [5, 6, 4, 4, 2, 1,      6, 4, 9, 4, 5, 4];var Max =math.max.apply (math,nums); Max value is 9 here is a trick, the key is the Math object as the first parameter of apply (), so that the correct setting of this value.
Rounding MethodMath.ceil (): Rounded up; Math.floor (): Rounded down; Math.Round (): Quasi-rounding, always rounding the value to the nearest integer.
The random () methodThe Math.random () method returns a random number between 0 and 1, excluding 0 and 1. With the following formula, you can use Math.random () to randomly select a value from within a range of certificatesRandom value = Math.floor (Math.random () * Total number of possible values + first possible value);
Other calculation methodsMath.Abs (x) returns the X absolute value math.exp (x) returns the NUM power of MATH.E Math.log (x) returns the X natural logarithm Math.pow (x) returns power times x Power math.sqrt (x) returns X Square root Math.acos (x) returns the inverse cosine of x math.asin (x) returns the inverse sine of x math.atan (x) returns the inverse tangent of x math.atan2 (y,x) returns the inverse tangent value of y/x math.cos (x) returns X Cosine Math.sin (x) returns the sinusoidal value of x Math.tan (x) returns the tangent of X

JavaScript reference types-built-in objects (Math object)

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.