The Math object
Programmers are often typecast as good mathematicians. While this is in fact
the case with me, I doubt it applies to everyone (small joke). As the scene
erupts in a sea of fury, lets just settle on the fact that every
the Math object. Want to calculate "2.5 to the power of 8" or "Sin0.9" in
Below lists all of Math's object's properties and methods:
||The constant of E, the base of natural logarithms.
||The natural logarithm of 2.
||The natural logarithm of 10.
||Base 2 logarithm of E.
||Base 10 logarithm of E.
||Square root of 1/2.
||Square root of 2.
||Returns absolute value of x.
||Returns arc cosine of x in radians.
||Returns arc sine of x in radians.
||Returns arc tan of x in radians.
||Counterclockwise angle between x axis and
||Returns the smallest integer greater than
or equal to x. (round up).
||Returns cosine of x, where x is in radians.
||Returns the largest
integer less than or equal to x. (round down)
||Returns the natural
logarithm (base E) of x.
||Returns the larger of a and b.
||Returns the lesser of a and b.
||Returns a pseudorandom number between 0 and
||Rounds x up or down to the nearest integer.
It rounds .5 up. Example(s).
||Returns the Sin of x, where x is in
||Returns the square root of x.
||Returns the Tan of x, where x is in
have baffled mankind for ages:
The "with" statement
If you intend to invoke Math multiple times in your
script, a good statement to remember is "with." Using it you can omit the
"Math." prefix for any subsequent Math properties/methods:
var x= sin(3.5)
And with that the tutorial comes to a wrap. Have fun
crunching some numbers!