ruby-changes:21360
From: naruse <ko1@a...>
Date: Wed, 5 Oct 2011 16:36:37 +0900 (JST)
Subject: [ruby-changes:21360] naruse:r33409 (trunk): Revert r33407; half-baked patch.
naruse 2011-10-05 16:36:28 +0900 (Wed, 05 Oct 2011) New Revision: 33409 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33409 Log: Revert r33407; half-baked patch. "* numeric.c (ruby_float_step): improve floating point calculations." Modified files: trunk/ChangeLog trunk/numeric.c trunk/test/ruby/test_float.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 33408) +++ ChangeLog (revision 33409) @@ -2,19 +2,6 @@ * vm_insnhelper.c (vm_call_cfunc): remove useless hack. -Wed Sep 21 11:17:22 2011 NARUSE, Yui <naruse@r...> - - * numeric.c (ruby_float_step): improve floating point calculations. - [ruby-core:35753] [Bug #4576] - - * numeric.c (ruby_float_step): correct the error of floating point - numbers on the excluding case. - patched by Masahiro Tanaka [ruby-core:39608] - - * numeric.c (ruby_float_step): use the end value when the current - value is greater than or equal to the end value. - patched by Akira Tanaka [ruby-core:39612] - Wed Oct 5 05:56:39 2011 Eric Hodel <drbrain@s...> * hash.c (Init_Hash): Improve Hash documentation. Patch by Alvaro Index: numeric.c =================================================================== --- numeric.c (revision 33408) +++ numeric.c (revision 33409) @@ -1690,26 +1690,11 @@ } else { if (err>0.5) err=0.5; - if (excl) { - if (n>0) { - if (n<err) - n = 1; - else - n = floor(n - err) + 1; - } - } else { - n = floor(n + err) + 1; + n = floor(n + err); + if (!excl || ((long)n)*unit+beg < end) n++; + for (i=0; i<n; i++) { + rb_yield(DBL2NUM(i*unit+beg)); } - if (end < (n-1)*unit+beg) { - for (i=0; i<n; i++) { - rb_yield(DBL2NUM((n-1-i)/(n-1)*beg+i/(n-1)*end)); - } - } - else { - for (i=0; i<n; i++) { - rb_yield(DBL2NUM(i*unit+beg)); - } - } } return TRUE; } Index: test/ruby/test_float.rb =================================================================== --- test/ruby/test_float.rb (revision 33408) +++ test/ruby/test_float.rb (revision 33409) @@ -508,35 +508,4 @@ sleep(0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1) end end - - def test_step - 1000.times do - a = rand - b = a+rand*1000 - s = (b - a) / 10 - assert_equal(11, (a..b).step(s).to_a.length) - end - - assert_equal(11, (1.0..(1.0+1E-15)).step(1E-16).to_a.length) - - (1.0..12.7).step(1.3).each do |n| - assert_operator(n, :<=, 12.7) - end - end - - def test_step_excl - 1000.times do - a = rand - b = a+rand*1000 - s = (b - a) / 10 - assert_equal(10, (a...b).step(s).to_a.length) - end - - assert_equal([1.0, 2.9, 4.8, 6.699999999999999], (1.0...6.8).step(1.9).to_a) - - e = 1+1E-12 - (1.0 ... e).step(1E-16) do |n| - assert_operator(n, :<, e) - end - end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/