Skip to content

Commit

Permalink
* lib/matrix: Add Matrix#round
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
marcandre committed Jul 1, 2011
1 parent f4dda52 commit 376b825
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Fri Jul 1 15:10:22 2011 Marc-Andre Lafortune <[email protected]>

* lib/matrix: Add Matrix#round

Fri Jul 1 11:41:12 2011 NARUSE, Yui <[email protected]>

* string.c (tr_trans): free heap ptr when the str is not embeded.
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ with all sufficient information, see the ChangeLog file.
* Matrix#normal?
* Matrix#orthogonal?
* Matrix#permutation?
* Matrix#round
* Matrix#symmetric?
* Matrix#unitary?
* Matrix#upper_triangular?
Expand Down
7 changes: 7 additions & 0 deletions lib/matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module ExceptionForMatrix # :nodoc:
# * <tt> #determinant </tt>
# * <tt> #det </tt>
# * <tt> #rank </tt>
# * <tt> #round </tt>
# * <tt> #trace </tt>
# * <tt> #tr </tt>
# * <tt> #transpose </tt>
Expand Down Expand Up @@ -1125,6 +1126,12 @@ def rank_e
rank
end

# Returns a matrix with entries rounded to the given precision
# (see Float#round)
#
def round(ndigits=0)
map{|e| e.round(ndigits)}
end

#
# Returns the trace (sum of diagonal elements) of the matrix.
Expand Down

0 comments on commit 376b825

Please sign in to comment.