Talking about the Math_javascript skill of JavaScript type system

Source: Internet
Author: User
Tags acos asin cos mathematical functions natural logarithm pow sin square root

Open the door must read

Unlike other objects, the Math object is a static object, not a constructor. In fact, math is just an object namespace set by JavaScript for storing mathematical functions

Property

MATH.E the base of the natural logarithm, which is the value of the constant E (approximately 2.718)
Value of Math.PI (approximately equal to 3.14159)
Console.log (MATH.E);//2.718281828459045
Console.log (Math.PI);//3.141592653589793
The natural logarithm of the MATH.LN2 2 (approximately equal to 0.693)
The natural logarithm of the math.ln10 10 (approximately equal to 2.302)
MATH.LOG2E 2 As the logarithm of the base e (approximately 1.414)
math.log10e 10 as the logarithm of the base e (approximately 0.434)
Console.log (MATH.LN2);//0.6931471805599453
Console.log (MATH.LN10);//2.302585092994046
Console.log (MATH.LOG2E);//1.4426950408889634
Console.log (math.log10e);//0.4342944819032518
Math.sqrt2 2 square root (approximately equal to 1.414)
The square root of the math.sqrt1_2 1/2, that is, the reciprocal of the square root of 2 (about 0.707)
Console.log (MATH.SQRT2);//1.4142135623730951
Console.log (math.sqrt1_2);//0.7071067811865476

Method

These methods involve number () implicit type conversion, and if the method scope is exceeded, it returns a Nan

Math.min () returns the smallest value in a set of numbers
Math.max () returns the maximum value in a set of numbers
Console.log (Math.min (1,2,3));//1
Console.log (Math.max (1,2,3));//3
Math.ceil (num) rounded up to an integer
Math.floor (num) is rounded down to an integer
Math.Round (num) rounded to an integer
Console.log (Math.ceil (12.6));//13
Console.log (Math.floor (12.6));//12
Console.log (Math.Round (12.6));//13
Math.Abs (num) returns the absolute value of num
Math.random () returns a random number that is greater than or equal to 0 less than 1
Console.log (Math.Abs (-10));//10
Console.log (Math.random ());//0.741887615993619
MATH.EXP (NUM) returns the NUM power of the MATH.E
Math.log (num) returns the natural logarithm of num
MATH.SQRT (num) returns the square root of num (x must be a number greater than or equal to 0)
Math.pow (Num,power) returns the power exponentiation of num
Console.log (math.exp (0));//1
Console.log (Math.log (10));//2.302585092994046
Console.log (MATH.SQRT (100));//10
Console.log (Math.pow (10,2));//100
Math.sin (x) returns the sine value of x
Math.Cos (x) returns the cosine of X
Math.tan (x) returns the tangent of X
Math.asin (x) returns the inverse chord value of x (x must be a number between 1 and 1)
Math.acos (x) returns the inverse cosine of x (x must be a number from 1 to 1)
Math.atan (x) returns the tangent value of X
Math.atan2 (y,x) returns the tangent value of y/x
Console.log (Math.sin (30*math.pi/180));//0.49999999999999994
Console.log (Math.Cos (60*math.pi/180));//0.5000000000000001
Console.log (Math.tan (45*math.pi/180));//0.9999999999999999
Console.log (Math.asin (1) *180/math.pi);//90
Console.log (Math.acos (1) *180/math.pi);//0
Console.log (Math.atan (1) *180/math.pi);//45
Console.log (Math.atan2 (1,1) *180/math.pi);//45

Tips

[TIPS1] finds the maximum or minimum value in an array

var values = [1,2,3,4,5,6,7,8];

[TIPS2] Randomly selects a value from an integer range

Value = Math.floor (Math.random () * Total number of possible values + first possible value)

[TIPS3] Randomly selects a value with minimum and maximum values

function Selectfrom (lowervalue,uppervalue) {
var choices = uppervalue-lowervalue + 1;
Return Math.floor (Math.random () *choices + lowervalue);
}
var num = Selectfrom (2,10);

Math Object method

Method Description
ABS (x) Returns the absolute value of a number.
ACOs (x) Returns the inverse cosine of a number.
ASIN (x) Returns the inverse chord value of a number.
Atan (x) Returns the inverse tangent of x to the value between-PI/2 and PI/2 radians.
ATAN2 (y,x) Returns the angle (between-PI/2 and PI/2 radians) from the X axis to point (X,y).
Ceil (x) The logarithm is rounded up.
COS (x) Returns the cosine of a number.
EXP (x) Returns the index of E.
Floor (x) The logarithm is rounded down.
Log (x) Returns the natural logarithm of the number (the bottom is e).
Max (X,y) Returns the highest value in X and Y.
Min (x,y) Returns the lowest value in X and Y.
Pow (x,y) Returns the Y-power of X.
Random () Returns the random number between 0 ~ 1.
Round (x) Round the number to the nearest integer.
Sin (x) Returns the sine of a number.
sqrt (x) Returns the square root of a number.
Tan (x) Returns the tangent of the angle.
Tosource () Returns the source code for this object.
ValueOf () Returns the original value of the Math object.

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.