End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Float#abs
float.abs → float
float.magnitude → float
numeric.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/numeric.rb, line 278
def abs
Primitive.attr! 'inline'
Primitive.cexpr! 'rb_float_abs(self)'
end
Returns the absolute value of float.
Example
(-34.56).abs #=> 34.56 -34.56.abs #=> 34.56 34.56.abs #=> 34.56
Float#magnitude is an alias for Float#abs.