public Method

Float.<=>(p1)

flt <→ numeric    -1, 0, +1

Returns -1, 0, or +1 depending on whether flt is less than, equal to, or greater than numeric. This is the basis for the tests in Comparable.

Source Code

/*
*  call-seq:
*     flt <=> numeric   => -1, 0, +1
*  
*  Returns -1, 0, or +1 depending on whether <i>flt</i> is less than,
*  equal to, or greater than <i>numeric</i>. This is the basis for the
*  tests in <code>Comparable</code>.
*/

static VALUE
flo_cmp(x, y)
   VALUE x, y;
{
   double a, b;

   a = RFLOAT(x)->value;
   switch (TYPE(y)) {
     case T_FIXNUM:
       b = (double)FIX2LONG(y);
       break;

     case T_BIGNUM:
       b = rb_big2dbl(y);
       break;

     case T_FLOAT:
       b = RFLOAT(y)->value;
       break;

     default:
       return rb_num_coerce_cmp(x, y);
   }
   return rb_dbl_cmp(a, b);
}
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.