* numeric.c (int_upto, int_downto): should fail unless the
argument is comparable. (ruby-bugs-ja:PR#454) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a03dd84dbc
commit
89c25a3dd6
@ -1,3 +1,8 @@
|
|||||||
|
Thu May 8 08:56:04 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
|
|
||||||
|
* numeric.c (int_upto, int_downto): should fail unless the
|
||||||
|
argument is comparable. (ruby-bugs-ja:PR#454)
|
||||||
|
|
||||||
Wed May 7 01:21:23 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Wed May 7 01:21:23 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* numeric.c (num_step): remove epsilon; add margin of 0.5, to make
|
* numeric.c (num_step): remove epsilon; add margin of 0.5, to make
|
||||||
|
28
numeric.c
28
numeric.c
@ -1653,6 +1653,28 @@ fix_size(fix)
|
|||||||
return INT2FIX(sizeof(long));
|
return INT2FIX(sizeof(long));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
int_compare(i, to, id)
|
||||||
|
VALUE i, to;
|
||||||
|
ID id;
|
||||||
|
{
|
||||||
|
VALUE cmp = rb_funcall(i, id, 1, to);
|
||||||
|
if (NIL_P(cmp)) {
|
||||||
|
char *toclass;
|
||||||
|
|
||||||
|
if (SPECIAL_CONST_P(to)) {
|
||||||
|
to = rb_inspect(to);
|
||||||
|
toclass = StringValuePtr(to);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
toclass = rb_obj_classname(to);
|
||||||
|
}
|
||||||
|
rb_raise(rb_eArgError, "cannot compare %s with %s",
|
||||||
|
rb_obj_classname(i), toclass);
|
||||||
|
}
|
||||||
|
return cmp;
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
int_upto(from, to)
|
int_upto(from, to)
|
||||||
VALUE from, to;
|
VALUE from, to;
|
||||||
@ -1668,8 +1690,7 @@ int_upto(from, to)
|
|||||||
else {
|
else {
|
||||||
VALUE i = from;
|
VALUE i = from;
|
||||||
|
|
||||||
for (;;) {
|
while (!int_compare(i, to, '>')) {
|
||||||
if (RTEST(rb_funcall(i, '>', 1, to))) break;
|
|
||||||
rb_yield(i);
|
rb_yield(i);
|
||||||
i = rb_funcall(i, '+', 1, INT2FIX(1));
|
i = rb_funcall(i, '+', 1, INT2FIX(1));
|
||||||
}
|
}
|
||||||
@ -1692,8 +1713,7 @@ int_downto(from, to)
|
|||||||
else {
|
else {
|
||||||
VALUE i = from;
|
VALUE i = from;
|
||||||
|
|
||||||
for (;;) {
|
while (!int_compare(i, to, '<')) {
|
||||||
if (RTEST(rb_funcall(i, '<', 1, to))) break;
|
|
||||||
rb_yield(i);
|
rb_yield(i);
|
||||||
i = rb_funcall(i, '-', 1, INT2FIX(1));
|
i = rb_funcall(i, '-', 1, INT2FIX(1));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user