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.atan2

(::Math::double y, ::Math::double x) -> ::Float
Math.atan2(y, x) → float

Returns the arc tangent of y and x in radians.

  • Domain of y: [-INFINITY, INFINITY].

  • Domain of x: [-INFINITY, INFINITY].

  • Range: [-PI, PI].

Examples:

Example
atan2(-1.0, -1.0) # => -2.356194490192345  # -3*PI/4
atan2(-1.0, 0.0)  # => -1.5707963267948966 # -PI/2
atan2(-1.0, 1.0)  # => -0.7853981633974483 # -PI/4
atan2(0.0, -1.0)  # => 3.141592653589793   # PI
See also .atan .atanh .asinh .cbrt also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0