Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Complex#abs

() -> ::Numeric
abs → float

Returns the absolute value (magnitude) for self; see polar coordinates:

Example
Complex.polar(-1, 0).abs # => 1.0

If self was created with rectangular coordinates, the returned value is computed, and may be inexact:

Example
Complex.rectangular(1, 1).abs # => 1.4142135623730951 # The square root of 2.
See also #== #abs2 #<=> #angle also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0