Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Decent sqrt()
  • Loading branch information
dankogai committed Jan 2, 2016
1 parent 3ea4dff commit 261993c
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 261993c

Please sign in to comment.