public Method

Float.hash

flt.hash    integer

Returns a hash code for this float.

Source Code

/*
* call-seq:
*   flt.hash   => integer
*
* Returns a hash code for this float.
*/

static VALUE
flo_hash(num)
   VALUE num;
{
   double d;
   char *c;
   int i, hash;

   d = RFLOAT(num)->value;
   if (d == 0) d = fabs(d);
   c = (char*)&d;
   for (hash=0, i=0; i<sizeof(double);i++) {
       hash = (hash * 971) ^ (unsigned char)c[i];
   }
   if (hash < 0) hash = -hash;
   return INT2FIX(hash);
}
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.