APIdock / Ruby
/
method

abs

ruby latest stable - Class: Integer
abs()
public

Returns the absolute value of int.

(-12345).abs  #=> 12345
-12345.abs  #=> 12345
12345.abs  #=> 12345

Integer#magnitude is an alias for Integer#abs.

VALUE
rb_int_abs(VALUE num)
{
 if (FIXNUM_P(num)) {
 return fix_abs(num);
 }
 else if (RB_TYPE_P(num, T_BIGNUM)) {
 return rb_big_abs(num);
 }
 return Qnil;
}

AltStyle によって変換されたページ (->オリジナル) /