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

Methods of the Math Object

The Math object's methods enable you to perform mathematical operations such as square roots, powers, and rounding, as well as trigonometry, logarithms, and more. All the Math object methods are summarized in Table 14.5, and I discuss many of these methods in the sections that follow.

Table 14.5. Methods of the Math Object
Method Syntax JavaScript Version What It Returns
Math.abs(Number) 1.0 The absolute value of Number (that is, the number without any sign)
Math.acos(Number) 1.0 The arccosine of Number (which must be between -1 and 1); returned values range from 0 to PI radians
Math.asin(Number) 1.0 The arcsine of Number (which must be between -1 and 1); returned values range from -PI/2 to PI/2 radians
Math.atan(Number) 1.0 The arctangent of Number; returned values range from -PI/2 to PI/2 radians
Math.atan2(y, x) 1.0 The arctangent of Iy>/x (where (x,y) is a Cartesian coordinate); returned values range from -PI/2 to PI/2 radians
Math.ceil(Number) 1.0 The smallest integer greater than or equal to Number
Math.cos(Number) 1.0 The cosine of Number; returned values range from -1 to 1 radians
Math.exp(Number) 1.0 E raised to the power of Number;
Math.floor(Number) 1.0 The largest integer that is less than or equal to Number
Math.log(Number) 1.0 The natural logarithm(base E) of Number
Math.max(Number1, Number2) 1.0 The larger of Number1 and Number2
Math.min(Number1, Number2) 1.0 The smaller of Number1 and Number2
Math.pow(Number1, Number2) 1.0 Number1 raised to the power of Number2
Math.random() 1.1 A random number between 0 and 1
Math.round(Number) 1.0 The integer closest to Number
Math.sin(Number) 1.0 The sine of Number; returned values range from -1 to 1 radians
Math.sqrt(Number) 1.0 The square root of Number (which must be greater than or equal to 0)
Math.tan(Number) 1.0 The tangent of Number, in radians
Math.toString(Number) 1.0 The string equivalent of Number



PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


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