• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 11. Manipulating Information > Calculating with the Math Class

Calculating with the Math Class

The Math class lets you access trigonometric functions such as sine, cosine, and tangent; logarithmic functions; rounding functions; and mathematical constants such as pi and e. Table 11.1 summarizes the methods and properties of the Math class. As with the Key, Mouse, Selection, and Stage classes, you don’t need to instantiate the Math class to call on its methods or properties, and all the Math class’s properties are read-only values that are written in all uppercase letters. You precede the method with the class name, Math.

Table 11.1. Methods and Properties of the Math Class
abs(number)Calculates the absolute value. Math.abs(-4) returns 4.
acos(number)Calculates the arc cosine.
asin(number)Calculates the arc sine.
atan(number)Calculates the arc tangent.
atan2(y, x)Calculates the angle (in radians) from the x-axis to a point on the y-axis.
ceil(number)Rounds the number up to the nearest integer. Math.ceil (2.34) returns 3.
cos(number)Calculates the cosine of an angle, in radians.
exp(number)Calculates the exponent of the constant e.
floor(number)Rounds the number down to the nearest integer. Math.floor (2.34) returns 2.
log(number)Calculates the natural logarithm.
max(x, y)Returns the larger of two values. Math.max (2, 7) returns 7.
min(x, y)Returns the smaller of two values. Math.min (2, 7) returns 2.
pow(base, exponent)Calculates the exponent of a number.
random()Returns a random number between 0 and 1 (including 0 but not including 1).
round(number)Rounds the number to the nearest integer. Math.round (2.34) returns 2.
sin(number)Calculates the sine of an angle, in radians.
sqrt(number)Calculates the square root.
tan(number)Calculates the tangent of an angle, in radians.
EEuler’s constant; the base of natural logarithms.
LN2The natural logarithm of 2.
LOG2EThe base-2 logarithm of e.
LN10The natural logarithm of 10.
LOG10EThe base-10 logarithm of e.
PIThe circumference of a circle divided by its diameter.
SQRT1_2The square root of 1/2.
SQRT2The square root of 2.



Not a subscriber?

Start A Free Trial

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint