ruby-changes:16069
From: nobu <ko1@a...>
Date: Wed, 26 May 2010 12:08:30 +0900 (JST)
Subject: [ruby-changes:16069] Ruby:r28018 (trunk, ruby_1_9_2): * random.c (random_rand): subtraction method of non-numeric can
nobu 2010-05-26 12:08:07 +0900 (Wed, 26 May 2010) New Revision: 28018 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28018 Log: * 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] Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/random.c branches/ruby_1_9_2/test/ruby/test_rand.rb trunk/ChangeLog trunk/random.c trunk/test/ruby/test_rand.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 28017) +++ ChangeLog (revision 28018) @@ -1,3 +1,9 @@ +Wed May 26 12:08:06 2010 Nobuyoshi Nakada <nobu@r...> + + * 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@s...> * marshal.c (Init_marshal): document marshal_dump and marshal_load. Index: test/ruby/test_rand.rb =================================================================== --- test/ruby/test_rand.rb (revision 28017) +++ test/ruby/test_rand.rb (revision 28018) @@ -357,6 +357,9 @@ 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 Index: random.c =================================================================== --- random.c (revision 28017) +++ random.c (revision 28018) @@ -1077,9 +1077,13 @@ 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); } Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 28017) +++ ruby_1_9_2/ChangeLog (revision 28018) @@ -1,3 +1,9 @@ +Wed May 26 12:08:06 2010 Nobuyoshi Nakada <nobu@r...> + + * 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 10:35:37 2010 Nobuyoshi Nakada <nobu@r...> * configure.in (rb_cv_large_fd_select): needed on mingw, even Index: ruby_1_9_2/test/ruby/test_rand.rb =================================================================== --- ruby_1_9_2/test/ruby/test_rand.rb (revision 28017) +++ ruby_1_9_2/test/ruby/test_rand.rb (revision 28018) @@ -357,6 +357,9 @@ 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 Index: ruby_1_9_2/random.c =================================================================== --- ruby_1_9_2/random.c (revision 28017) +++ ruby_1_9_2/random.c (revision 28018) @@ -1077,9 +1077,13 @@ 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); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/