Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

Math.cos

Math.cos(x) → float

Returns the cosine of x in radians.

  • Domain: (-INFINITY, INFINITY).

  • Range: [-1.0, 1.0].

Examples:

Example
cos(-PI)   # => -1.0
cos(-PI/2) # => 6.123031769111886e-17 # 0.0000000000000001
cos(0.0)   # => 1.0
cos(PI/2)  # => 6.123031769111886e-17 # 0.0000000000000001
cos(PI)    # => -1.0
See also .cbrt .cosh .atanh .erf also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0