* random.c (random_rand): refined error message.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
31875e97b4
commit
2981448f33
@ -1,4 +1,6 @@
|
|||||||
Wed Aug 26 23:58:39 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Aug 26 23:59:56 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* random.c (random_rand): refined error message.
|
||||||
|
|
||||||
* random.c (random_rand): fixed for edge cases of ranges.
|
* random.c (random_rand): fixed for edge cases of ranges.
|
||||||
[ruby-dev:39166]
|
[ruby-dev:39166]
|
||||||
|
29
random.c
29
random.c
@ -902,13 +902,6 @@ range_values(VALUE vmax, VALUE *begp, int *exclp)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline VALUE
|
|
||||||
add_to_begin(VALUE beg, VALUE offset)
|
|
||||||
{
|
|
||||||
if (beg == Qundef) return offset;
|
|
||||||
return rb_funcall2(beg, id_plus, 1, &offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rand_int(struct MT *mt, VALUE vmax, int restrictive)
|
rand_int(struct MT *mt, VALUE vmax, int restrictive)
|
||||||
{
|
{
|
||||||
@ -1049,10 +1042,28 @@ random_rand(int argc, VALUE *argv, VALUE obj)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
v = Qnil;
|
||||||
NUM2LONG(vmax);
|
NUM2LONG(vmax);
|
||||||
}
|
}
|
||||||
if (NIL_P(v)) rb_raise(rb_eArgError, "invalid argument");
|
if (NIL_P(v)) {
|
||||||
return add_to_begin(beg, v);
|
VALUE mesg = rb_str_new_cstr("invalid argument - ");
|
||||||
|
rb_str_append(mesg, rb_obj_as_string(argv[0]));
|
||||||
|
rb_exc_raise(rb_exc_new3(rb_eArgError, mesg));
|
||||||
|
}
|
||||||
|
if (beg == Qundef) return v;
|
||||||
|
if (FIXNUM_P(beg) && FIXNUM_P(v)) {
|
||||||
|
long x = FIX2LONG(beg) + FIX2LONG(v);
|
||||||
|
return LONG2NUM(x);
|
||||||
|
}
|
||||||
|
switch (BUILTIN_TYPE(v)) {
|
||||||
|
case T_BIGNUM:
|
||||||
|
return rb_big_plus(v, beg);
|
||||||
|
case T_FLOAT:
|
||||||
|
RFLOAT_VALUE(v) += RFLOAT_VALUE(rb_check_to_float(beg));
|
||||||
|
return v;
|
||||||
|
default:
|
||||||
|
return rb_funcall2(v, id_plus, 1, &beg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user