The math.sin function returns the sine of a given angle, which is expressed in radians. This function is part of the mathematical library in lua, allowing for trigonometric calculations.

Syntax

math.sin(x)

Parameters

  • x: A number representing an angle in radians.

Return Value

Returns the sine of x, which will be a value between -1 and 1, inclusive. If x is Infinity, -Infinity, or NaN, the function will return NaN.

Description

The math.sin function computes the sine of the specified angle in radians. Since sin is a static method of the math library, it is always used in the form math.sin() and not as a method of a math object.

Examples

Basic usage of math.sin()

print(math.sin(0))             -- Output: 0
print(math.sin(math.pi / 2))   -- Output: 1
print(math.sin(math.pi))        -- Output: 0
print(math.sin(-math.pi / 2))  -- Output: -1
print(math.sin(-Infinity))      -- Output: NaN
print(math.sin(NaN))            -- Output: NaN

See also

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

Was this page helpful?

Table of Contents