* array.c (rb_ary_sum): apply the precision compensated algorithm
for an array in which Rational and Float values are mixed.
* test/ruby/test_array.rb (test_sum): add assertions for the above
change.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Kahan's compensated summation algorithm for precise sum of float
numbers is moved from ary_inject_op in enum.c.
* enum.c (ary_inject_op): Don't specialize for float numbers.
[ruby-core:74569] [Feature#12217] proposed by mrkn.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54565 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
[Feature #12172]
* internal.h (OPTIMIZED_CMP): moved from enum.c so that array.c can
use it.
* test/ruby/test_array.rb (test_max, test_min): tests for Array#max
and Array#min.
* test/ruby/test_enum.rb (test_max, test_min): revised a bit to test
Enumerable#max and #min explicitly.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (rb_ary_push_m): [DOC] Remove trailing comma from
Array#push example, as other Array examples doesn't put trailing
comma. [Fix GH-1279]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (rb_ary_and): clarify that set intersection returns the
unique elements common to both arrays.
* array.c (rb_ary_or): clarify that union preserves the order from
the given arrays.
- Most know what intersection means, but saying the operation
excludes duplicates could be misleading ([1] & [1], duplicates
excluded, might mean a result of []).
- Instead, saying intersection returns the unique elements common to both
arrays is more concise and less ambiguous.
- The set union's documentation was incomplete in its describing
preservation of order. Saying union preserves the order of the
original array neglects the idea that the order of the elements
in both arrays, as given, will be preserved.
- Instead, saying set union preserves the order from the given arrays (and
adding an example) fully demonstrates the idea.
[Fix GH-1273] [ci skip]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53958 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (rb_ary_dig): [DOC] fix the exception class to be raised
when intermediate object does not have dig method. TypeError
will be raised now. [Fix GH-1224]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* error.c (rb_assert_failure): assertion with stack dump.
* ruby_assert.h (RUBY_ASSERT): new header for the assertion.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
[#11776]
* hash.c: ditto
* struct.c: ditto
* test_hash.rb: Add basic test for user defined `dig`.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52941 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* internal.h (RUBY_DTRACE_CREATE_HOOK): macro to call hook at
object creation.
* vm.c (rb_source_location, rb_source_loc): retrieve source path
and line number at once.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (rb_ary_collect): [DOC] Fix space of code example of
Array#map. [Fix GH-1062]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (rb_ary_sort_bang, rb_ary_sort): [DOC] correct block
return values, which may be a negative or positive integer, not
ony -1 or +1.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51860 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (rb_ary_sort_bang, rb_ary_sort): [DOC] Correct
description of array sort block return values. And also fix up
the grammar a bit. [Fix GH-1020]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (rb_ary_sort_bang): the original array may not be
embedded even if a substitution array is embedded, as it is
embedded when the original array is short enough but not
embedded. [ruby-dev:49166] [Bug #11332]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51147 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (rb_ary_bsearch_index): fix function typt to return
enumerator if no block given.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (rb_ary_bsearch_index): Implement Array#bsearch_index
method, which is similar to bsearch and returns the index or
nil. [Feature #10730]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50839 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (rb_ary_assoc, rb_ary_rassoc): [DOC] the result when key
was found is the existing element, not a new array. reported by
Giau Nguyen <giaunv AT nustechnology.com>.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (flatten): no need to call to_ary method on elements
beyond the given level. [ruby-core:67637] [Bug #10748]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49400 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (rb_ary_bsearch): trivial optimizations, for Fixnum, and
by keeping the last satisfied element.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* array.c (rb_ary_bsearch): preserve encoding of class name in an
exception message.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49215 b2dd03c8-39d4-4d8f-98ff-823fe69b080e