diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-05-26 03:08:07 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-05-26 03:08:07 +0000 |
commit | 9dae7d94f9ede71783523e134f89512bdd55f5ac (patch) | |
tree | 0aef7f470cd36aab06ad82a22729572e923bef33 /random.c | |
parent | 459d624366335ed3a5d3ea817ba3c19a1cb66c14 (diff) |
* random.c (random_rand): subtraction method of non-numeric can
return Float, and add the result of random to the beginning of
range, not the opposite. [ruby-dev:41410]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@28018 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'random.c')
-rw-r--r-- | random.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -1077,9 +1077,13 @@ random_rand(int argc, VALUE *argv, VALUE obj) switch (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; + case T_FLOAT: { + VALUE f = rb_check_to_float(beg); + if (!NIL_P(f)) { + RFLOAT_VALUE(v) += RFLOAT_VALUE(f); + return v; + } + } default: return rb_funcall2(v, id_plus, 1, &beg); } |