ruby-changes:15317
From: nobu <ko1@a...>
Date: Sat, 3 Apr 2010 10:52:00 +0900 (JST)
Subject: [ruby-changes:15317] Ruby:r27204 (trunk): * random.c (random_rand): raise ArgumentError on nil, as the
nobu 2010-04-03 10:51:26 +0900 (Sat, 03 Apr 2010) New Revision: 27204 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=27204 Log: * random.c (random_rand): raise ArgumentError on nil, as the documentation implies. [ruby-core:29075] * random.c (rb_f_rand): mentioned the case of when max is nil. Modified files: trunk/ChangeLog trunk/random.c trunk/test/ruby/test_rand.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 27203) +++ ChangeLog (revision 27204) @@ -1,3 +1,10 @@ +Sat Apr 3 10:51:10 2010 Nobuyoshi Nakada <nobu@r...> + + * random.c (random_rand): raise ArgumentError on nil, as the + documentation implies. [ruby-core:29075] + + * random.c (rb_f_rand): mentioned the case of when max is nil. + Sat Apr 3 06:56:11 2010 Marc-Andre Lafortune <ruby-core@m...> * array.c (rb_ary_product): Accept a block [ruby-core:29045] Index: test/ruby/test_rand.rb =================================================================== --- test/ruby/test_rand.rb (revision 27203) +++ test/ruby/test_rand.rb (revision 27204) @@ -207,6 +207,7 @@ assert_raise(ArgumentError, '[ruby-dev:39166]') { r.rand(0..-1) } assert_raise(ArgumentError, '[ruby-dev:39166]') { r.rand(0.0...0.0) } assert_raise(ArgumentError, '[ruby-dev:39166]') { r.rand(0.0...-0.1) } + assert_raise(ArgumentError, bug3027 = '[ruby-core:29075]') { r.rand(nil) } end def test_random_seed Index: random.c =================================================================== --- random.c (revision 27203) +++ random.c (revision 27204) @@ -989,7 +989,6 @@ int excl = 0; if (argc == 0) { - zero_arg: return rb_float_new(genrand_real(&rnd->mt)); } else if (argc != 1) { @@ -997,7 +996,7 @@ } vmax = argv[0]; if (NIL_P(vmax)) { - goto zero_arg; + v = Qnil; } else if (TYPE(vmax) != T_FLOAT && (v = rb_check_to_integer(vmax, "to_int"), !NIL_P(v))) { v = rand_int(&rnd->mt, vmax = v, 1); @@ -1098,7 +1097,7 @@ * rand(max=0) => number * * Converts <i>max</i> to an integer using max1 = - * max<code>.to_i.abs</code>. If the result is zero, returns a + * max<code>.to_i.abs</code>. If _max_ is +nil+ the result is zero, returns a * pseudorandom floating point number greater than or equal to 0.0 and * less than 1.0. Otherwise, returns a pseudorandom integer greater * than or equal to zero and less than max1. <code>Kernel::srand</code> -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/