ruby-changes:33126
From: marcandre <ko1@a...>
Date: Fri, 28 Feb 2014 11:03:35 +0900 (JST)
Subject: [ruby-changes:33126] marcandRe: r45205 (trunk): * numeric.c: Simplify [Bug #9570]
marcandre 2014-02-28 11:03:30 +0900 (Fri, 28 Feb 2014) New Revision: 45205 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45205 Log: * numeric.c: Simplify [ruby-core:61106] [Bug #9570] Modified files: trunk/numeric.c Index: numeric.c =================================================================== --- numeric.c (revision 45204) +++ numeric.c (revision 45205) @@ -1805,26 +1805,22 @@ VALUE https://github.com/ruby/ruby/blob/trunk/numeric.c#L1805 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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/