Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

class method

Math.cos

(::Math::double x) -> ::Float
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.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0