public Method

Float.==(p1)

flt == obj    true or false

Returns true only if obj has the same value as flt. Contrast this with Float#eql?, which requires obj to be a Float.

1.0 == 1   #=> true

Source Code

/*
*  call-seq:
*     flt == obj   => true or false
*  
*  Returns <code>true</code> only if <i>obj</i> has the same value
*  as <i>flt</i>. Contrast this with <code>Float#eql?</code>, which
*  requires <i>obj</i> to be a <code>Float</code>.
*     
*     1.0 == 1   #=> true
*     
*/

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

   switch (TYPE(y)) {
     case T_FIXNUM:
       b = FIX2LONG(y);
       break;
     case T_BIGNUM:
       b = rb_big2dbl(y);
       break;
     case T_FLOAT:
       b = RFLOAT(y)->value;
       if (isnan(b)) return Qfalse;
       break;
     default:
       return num_equal(x, y);
   }
   a = RFLOAT(x)->value;
   if (isnan(a)) return Qfalse;
   return (a == b)?Qtrue:Qfalse;
}
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.