diff --git a/ChangeLog b/ChangeLog index 5cdfe6ceda..01561021a7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Fri Jul 1 15:10:22 2011 Marc-Andre Lafortune + + * lib/matrix: Add Matrix#round + Fri Jul 1 11:41:12 2011 NARUSE, Yui * string.c (tr_trans): free heap ptr when the str is not embeded. diff --git a/NEWS b/NEWS index 1ce506dda2..1fd0a0c010 100644 --- a/NEWS +++ b/NEWS @@ -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? diff --git a/lib/matrix.rb b/lib/matrix.rb index 3242cde9b2..12f99925bc 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -89,6 +89,7 @@ end # * #determinant # * #det # * #rank +# * #round # * #trace # * #tr # * #transpose @@ -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.