Skip to content

Commit

Permalink
Consolidate muliptlication into one place
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonmcdonald committed May 13, 2014
1 parent 01988e3 commit f0fed9d
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/vm.c
Expand Up @@ -1729,19 +1729,24 @@ mrb_context_run(mrb_state *mrb, struct RProc *proc, mrb_value self, unsigned int
switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {
case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM):
{
mrb_int x, y, z;
mrb_value z;

x = mrb_fixnum(regs[a]);
y = mrb_fixnum(regs[a+1]);
z = x * y;
#ifdef MRB_WORD_BOXING
z = (z << MRB_FIXNUM_SHIFT) / (1 << MRB_FIXNUM_SHIFT);
#endif
if (x != 0 && z/x != y) {
SET_FLT_VALUE(mrb, regs[a], (mrb_float)x * (mrb_float)y);
}
else {
SET_INT_VALUE(regs[a], z);
z = mrb_fixnum_mul(mrb, regs[a], regs[a+1]);

switch (mrb_type(z)) {
case MRB_TT_FIXNUM:
{
SET_INT_VALUE(regs[a], mrb_fixnum(z));
}
break;
case MRB_TT_FLOAT:
{
SET_FLT_VALUE(mrb, regs[a], mrb_float(z));
}
break;
default:
/* cannot happen */
break;
}
}
break;
Expand Down

0 comments on commit f0fed9d

Please sign in to comment.