diff --git a/numeric.c b/numeric.c index 99a1c7d60e..88fff399c7 100644 --- a/numeric.c +++ b/numeric.c @@ -1805,26 +1805,22 @@ VALUE ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl) { if (FIXNUM_P(from) && FIXNUM_P(to) && FIXNUM_P(step)) { - long delta, diff, result; + long delta, diff; diff = FIX2LONG(step); if (!diff) rb_num_zerodiv(); delta = FIX2LONG(to) - FIX2LONG(from); + if (diff < 0) { + diff = -diff; + delta = -delta; + } if (excl) { - delta += (diff > 0 ? -1 : +1); + delta--; } - if (delta) { - if (diff < 0) { - if (delta > 0) return INT2FIX(0); - diff = -diff; - delta = -delta; - } - else { - if (delta < 0) return INT2FIX(0); - } + if (delta < 0) { + return INT2FIX(0); } - result = delta / diff; - return LONG2FIX(result >= 0 ? result + 1 : 0); + return LONG2FIX(delta / diff + 1); } else if (RB_TYPE_P(from, T_FLOAT) || RB_TYPE_P(to, T_FLOAT) || RB_TYPE_P(step, T_FLOAT)) { double n = ruby_float_step_size(NUM2DBL(from), NUM2DBL(to), NUM2DBL(step), excl);