Visit Mozilla.org

Core JavaScript 1.5 Reference:Global Objects:Math:cos

From MDC


Contents

[edit] Summary

Returns the cosine of a number.

Method of Math

Static

Implemented in: JavaScript 1.0, NES 2.0
ECMA Version: ECMA-262

[edit] Syntax

Math.cos(x)

[edit] Parameters

x 
A number.

[edit] Description

The cos method returns a numeric value between -1 and 1, which represents the cosine of the angle.

Because cos is a static method of Math, you always use it as Math.cos(), rather than as a method of a Math object you created.

[edit] Examples

[edit] Example: Using Math.cos

The following function returns the cosine of the variable x:

function getCos(x) {
   return Math.cos(x)
}

If x equals 2*Math.PI, getCos returns 1; if x equals Math.PI, the getCos method returns -1.

[edit] See Also

acos, asin, atan, atan2, sin, tan