diff --git a/lib/Math/Vector.pm b/lib/Math/Vector.pm index ee209ac..7a427a9 100644 --- a/lib/Math/Vector.pm +++ b/lib/Math/Vector.pm @@ -46,9 +46,14 @@ class Math::Vector $a ⋅ $b; } + method conjugate() + { + return Math::Vector.new(@.coordinates>>.conjugate); + } + method Length() { - sqrt(self ⋅ self); + sqrt(self ⋅ self.conjugate).abs; } multi method abs() diff --git a/t/01-basics.t b/t/01-basics.t index 75721ee..87cedff 100644 --- a/t/01-basics.t +++ b/t/01-basics.t @@ -207,4 +207,7 @@ isa_ok($vl, Math::VectorWithLength, "Variable is of type Math::VectorWithLength" my $vlc = eval($vl.perl); isa_ok($vlc, Math::VectorWithLength, "eval'd perl'd variable is of type Math::VectorWithLength"); +my $complex_vector = Math::Vector.new(0, 3+4i); +is($complex_vector.abs, 5, "length of vector with complex vector is real"); + done;