1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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/trunk@28018 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-05-26 03:08:07 +00:00
parent dd8d4f0075
commit 93bbd7869c
3 changed files with 16 additions and 3 deletions

View file

@ -1,3 +1,9 @@
Wed May 26 12:08:06 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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]
Wed May 26 11:50:09 2010 Eric Hodel <drbrain@segment7.net>
* marshal.c (Init_marshal): document marshal_dump and marshal_load.

View file

@ -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);
}

View file

@ -357,6 +357,9 @@ END
v = r.rand(3.1..4)
assert_instance_of(Float, v, '[ruby-core:24679]')
assert_includes(3.1..4, v)
now = Time.now
assert_equal(now, r.rand(now..now))
end
def test_random_float