summaryrefslogtreecommitdiff
path: root/lib/matrix.rb
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-01 06:10:40 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-01 06:10:40 +0000
commit376b8251271da10ff3571b9a15c25333bb4492bc (patch)
tree95b2aba8da9527ba989706632a2814bd5d9d7c6e /lib/matrix.rb
parentf4dda52025433e232f931ffa1cb0473684128a5a (diff)
* lib/matrix: Add Matrix#round
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32350 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/matrix.rb')
-rw-r--r--lib/matrix.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb
index 3242cde..12f9992 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -89,6 +89,7 @@ end
# * <tt> #determinant </tt>
# * <tt> #det </tt>
# * <tt> #rank </tt>
+# * <tt> #round </tt>
# * <tt> #trace </tt>
# * <tt> #tr </tt>
# * <tt> #transpose </tt>
@@ -1125,6 +1126,12 @@ class Matrix
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.