зеркало из https://github.com/github/ruby.git
* numeric.c: Simplify [ruby-core:61106] [Bug #9570]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
debb5e4cb7
Коммит
e184e31c09
16
numeric.c
16
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 (excl) {
|
||||
delta += (diff > 0 ? -1 : +1);
|
||||
}
|
||||
if (delta) {
|
||||
if (diff < 0) {
|
||||
if (delta > 0) return INT2FIX(0);
|
||||
diff = -diff;
|
||||
delta = -delta;
|
||||
}
|
||||
else {
|
||||
if (delta < 0) return INT2FIX(0);
|
||||
if (excl) {
|
||||
delta--;
|
||||
}
|
||||
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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче