math.cos(x)

The math.cos() function in lua returns the cosine of a number, assuming the number is in radians.


Syntax

math.cos(x)

Parameters

  • x
    A number representing an angle in radians.

Return value

The cosine of x, which is a number between -1 and 1, inclusive. If x is Infinity, -Infinity, or NaN, it returns NaN.


Description

Because math.cos() is a static function, it is always used as math.cos(), rather than as a method of a lua object. This function is useful for performing calculations involving angles in trigonometry.


Examples

Using math.cos()

print(math.cos(-Infinity))  -- NaN
print(math.cos(-0))         -- 1
print(math.cos(0))          -- 1
print(math.cos(1))          -- 0.5403023058681398
print(math.cos(math.pi))    -- -1
print(math.cos(2 * math.pi)) -- 1
print(math.cos(Infinity))   -- NaN

See also

  • math.acos()
  • math.asin()
  • math.atan()
  • math.atan2()
  • math.sin()
  • math.tan()

Was this page helpful?

Table of Contents