public Method

Fixnum.abs

fix.abs  aFixnum

Returns the absolute value of fix.

-12345.abs   #=> 12345
12345.abs    #=> 12345

Source Code

/*
*  call-seq:
*     fix.abs -> aFixnum
*  
*  Returns the absolute value of <i>fix</i>.
*     
*     -12345.abs   #=> 12345
*     12345.abs    #=> 12345
*     
*/

static VALUE
fix_abs(fix)
   VALUE fix;
{
   long i = FIX2LONG(fix);

   if (i < 0) i = -i;

   return LONG2NUM(i);
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.