Attributes of the Math object
E: Value e, bottom of the natural logarithm
LN10: the natural logarithm of 10
LN2: natural logarithm of 2
LOG2E: Base-2 logarithm of E
LOG10E: Base-10 logarithm of E
PI: Value Delivery
SQRT1_2: the square root of 1/2
SQRT2: square root of 2
Math object method: maximum value and minimum value
Min () & max () is used to obtain the minimum and maximum values of a group of numbers.
Example:
Copy codeThe Code is as follows:
Var iMax = Math. Max (1, 2, 3 );
Alert (iMax); // outputs 3
Var iMin = Math. Min (1, 2, 3 );
Alert (iMin); // outputs 1
Approx. Pair Value
Abs () is used to return the absolute value of a number.
Example:
Copy codeThe Code is as follows:
Var iNegOne = Math. abs (-1 );
Alert (iNegOne); // oupputs 1
Var iPosOne = Math. abs (1 );
Alert (iPosOne); // outputs 1
Round decimal places to Integers
Ceil () is the rounded up function, which always rounds the number up to the nearest value.
Floor () is a downward rounding function, which always places numbers down to the nearest value.
Round () is rounded to the rounding method.
Example:
Copy codeThe Code is as follows:
Alert (Math. ceil (25.5); // oputpus 26
Alert (Math. floor (25.5); // oputpus 25
Alert (Math. round (25.5); // oputpus 26
Exponential computing
Exp () is used to raise Math. eto the specified power.
Log () is used to return the natural logarithm of a specific number.
Pow () is used to raise a specified number to a specified power.
Sqrt () is used to return the square root of a specified number.
Trigonometric function method
Acos (x) is used to return the arc cosine of x.
Asin (x) is used to return the arc sine of x.
Atan (x) returns the arc tangent of x.
Atan2 (y, x) is used to return the arc cosine of y/x.
Cos (x) is used to return the cosine of x.
Sin (x) is used to return the sine of x.
Tan (x) returns the tangent of x.
Random Number Function
Random () is used to return a random number ranging from 0 to 1, excluding 0 and 1.
Select a random number within a range:
Copy codeThe Code is as follows:
Function selectFrom (iFirstValue, iLastValue ){
Var iChoices = iLastValue-iFirstValue + 1;
Return Math. floor (Math. random () * iChoices + iFirstValue );
}
// Demo
Var iNum = selectFrom (2, 10 );
Author: Artwl
Source: http://artwl.cnblogs.com