public Method

Fixnum.*(p1)

fix * numeric     numeric_result

Performs multiplication: the class of the resulting object depends on the class of numeric and on the magnitude of the result.

Source Code

/*
* call-seq:
*   fix * numeric   =>  numeric_result
*
* Performs multiplication: the class of the resulting object depends on
* the class of <code>numeric</code> and on the magnitude of the 
* result.
*/

static VALUE
fix_mul(x, y)
   VALUE x, y;
{
   if (FIXNUM_P(y)) {
#ifdef __HP_cc
       /* avoids an optimization bug of HP aC++/ANSI C B3910B A.06.05 [Jul 25 2005] */
       volatile
#endif
       long a, b, c;
       VALUE r;

       a = FIX2LONG(x);
       if (a == 0) return x;

       b = FIX2LONG(y);
       c = a * b;
       r = LONG2FIX(c);

       if (FIX2LONG(r) != c || c/a != b) {
           r = rb_big_mul(rb_int2big(a), rb_int2big(b));
       }
       return r;
   }
   if (TYPE(y) == T_FLOAT) {
       return rb_float_new((double)FIX2LONG(x) * RFLOAT(y)->value);
   }
   return rb_num_coerce_bin(x, y);
}
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.