Example #1
0
static mrb_value
fix_rshift(mrb_state *mrb, mrb_value x)
{
  mrb_int width;
  mrb_value result;

  fix_shift_get_width(mrb, &width);

  if (width == 0) {
    result = x;
  }
  else {
    mrb_int val;

    val = mrb_fixnum(x);
    if (width < 0) {
      result = lshift(mrb, val, -width);
    }
    else {
      result = rshift(val, width);
    }
  }

  return result;
}
Example #2
0
static mrb_value
fix_lshift(mrb_state *mrb, mrb_value x)
{
  mrb_int width, val;

  fix_shift_get_width(mrb, &width);

  if (width == 0) {
    return x;
  }
  val = mrb_fixnum(x);
  if (width < 0) {
    return rshift(val, -width);
  }
  return lshift(mrb, val, width);
}