Math

Objectives

  • Use some common Math constants
  • Use some common Math functions

Math constants

  • Math.E: e (the base of the natural logarithm)
  • Math.PI: Pi
  • Math.LN10: the natural logarithm of 10
  • Math.LN2: the natural logarithm of 2
  • Math.LOG10E: the base 10 logarithm of e
  • Math.LOG2E: the base 2 logarithm of e
  • Math.SQRT1_2: 1 divided by the square root of 2
  • Math.SQRT2: the square root of 2

Math functions

  • Math.abs(n): absolute value of n
  • Math.ceil(n): rounds n up
  • Math.floor(n): rounds n down
  • Math.round(n): rounds n to the nearest integer
  • Math.min(a, b): returns the smaller of a and b
  • Math.max(a, b): returns the larger of a and b
  • Math.random(): returns a random number from 0.0 to less than 1.0
  • Math.pow(a, b): returns a to the b power
  • Math.sqrt(n): returns the square root of n
  • Math.log(n): returns natural logarithm of n
  • Math.exp(n): computes e raised to the power n
  • Math.acos(x): computes arccosine of x
  • Math.asin(x): computes arcsine of x
  • Math.atan(x): computes arctangent of x
  • Math.atan2(y, x): computes arctangent of y/x
  • Math.cos(r): computes cosine of angle r (in radians)
  • Math.sin(r): computes sine of angle r (in radians)
  • Math.tan(r): computes tangent of angle r (in radians)

Example of using Math