summaryrefslogtreecommitdiff
path: root/lib/matrix.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-03 05:49:06 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-03 05:49:06 +0000
commit7c2230bd8c8a16a976091f983737d94ce52959d1 (patch)
tree4514272cb7d8e21b44593c0b3dd7c8ea8146ca18 /lib/matrix.rb
parenta4ce3ab4fd5982af49662320839f8ec109d63881 (diff)
matrix.rb: complex vector
* lib/matrix.rb (Vector#magnitude): accumulate squares of absolute values to fix for complex vector. [ruby-dev:46100] [Bug #6966] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36887 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/matrix.rb')
-rw-r--r--lib/matrix.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb
index 8f57c73..00fa762 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -1770,7 +1770,7 @@ class Vector
# Vector[5,8,2].r => 9.643650761
#
def magnitude
- Math.sqrt(@elements.inject(0) {|v, e| v + e*e})
+ Math.sqrt(@elements.inject(0) {|v, e| v + e.abs2})
end
alias r magnitude
alias norm magnitude