Jump to content

User:Wogga62/Sandbox

From Wikipedia, the free encyclopedia

The Math object is always available. (Note that it is an object, not a constructor like Array or Date.) It has a number of Properties which return useful constants and also a number of Methods which provide access to mathematical functions such as Cosine and Square Root. All the trigonometric functions use angles expressed in radians; not degrees or grads. (One Radian is about 57.296°.)

PROPERTIES of the Math object
Property Value Returned
rounded to 5 digits
Description
Math.E 2.7183 Euler's constant, also known as e
Math.LN2 0.69315 Natural logarithm of 2
Math.LN10 2.3026 Natural logarithm of 10
Math.LOG2E 1.4427 Logarithm to the base 2 of e
Math.LOG10E 0.43429 Logarithm to the base 10 of e
Math.PI 3.1416 π : circumference/diameter of a circle
Math.SQRT1_2 0.70711 Square root of a half
Math.SQRT2 1.4142 Square root of 2
METHODS of the Math object
Example Value Returned
rounded to 5 digits
Description
Math.abs(-2.3) 2.3 Absolute value : (x < 0) ? -x : x
Math.acos(Math.SQRT1_2) 0.78540 rad. = 45° Arc Cosine
Math.asin(Math.SQRT1_2) 0.78540 rad. = 45° Arc Sine
Math.atan(1) 0.78540 rad. = 45° Half Circle Arc Tangent. -Pi/2 to +Pi/2
Math.atan2(-3.7, -3.7) -2.3562 rad. = -135° Whole Circle Arc Tangent. -Pi to +Pi
Math.ceil(1.1) 2 Ceiling : next integer >= argument
Math.cos(Math.PI/4) 0.70711 Cosine trigonometric function : rad. input
Math.exp(1) 2.7183 Exponential Function : e raised to this power
Math.floor(1.9) 1 Floor : next integer <= argument
Math.log(Math.E) 1 Natural Logarithm, base e
Math.max(1, -2) 1 Maximum : (x > y) ? x : y
Math.min(1, -2) -2 Minimum : (x < y) ? x : y
Math.pow(-3, 2) 9 To the power of : Math.pow(x, y) gives xy
Math.random() 0.17068 Random number from 0 to 1
Math.round(1.5) 2 Round to the nearest counting number
Math.sin(Math.PI/4) 0.70711 Sine trigonometric function : rad. input
Math.sqrt(49) 7 Square Root
Math.tan(Math.PI/4) 1 Tangent trigonometric function : rad. input

There are one or two other Methods available in some recent software. See http://www.w3schools.com/jsref/jsref_obj_math.asp

Example of uses of the Math object

where = ( a*Math.sin(ang) + b*Math.cos(ang) > Math.sqrt(r2) ) ? "outside" : "inside"