Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #667 from dankogai/nom
Decent sqrt()
  • Loading branch information
lizmat committed Jan 2, 2016
2 parents 3ea4dff + 261993c commit b8a75b9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/Complex.pm
Expand Up @@ -80,8 +80,10 @@ my class Complex is Cool does Numeric {
}

method sqrt(Complex:D:) {
my Num ($mag, $angle) = self.polar;
$mag.sqrt.unpolar($angle/2);
my Num $abs = self.abs;
my Num $re = (($abs + self.re)/2).sqrt;
my Num $im = (($abs - self.re)/2).sqrt;
Complex.new($re, self.im < 0 ?? -$im !! $im);
}

multi method exp(Complex:D:) {
Expand Down

0 comments on commit b8a75b9

Please sign in to comment.