Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
prefix:<abs>(Complex)
  • Loading branch information
moritz committed Oct 16, 2011
1 parent ea25f3e commit aa1ea2a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/core/Complex.pm
Expand Up @@ -187,7 +187,7 @@ my class Complex is Numeric {
}
}

multi sub prefix:<->(Complex:D \$a) {
multi sub prefix:<->(Complex:D \$a) returns Complex:D {
my $new := nqp::create(Complex);
nqp::bindattr_n( $new, Complex, '$!re',
nqp::neg_n(
Expand All @@ -202,6 +202,13 @@ multi sub prefix:<->(Complex:D \$a) {
$new;
}

multi sub prefix:<abs>(Complex:D \$a) {
my num $re = nqp::getattr_n(pir::perl6_decontainerize__PP($a), Complex, '$!re');
my num $im = nqp::getattr_n(pir::perl6_decontainerize__PP($a), Complex, '$!im');
my num $res = pir::sqrt__NN(nqp::add_n(nqp::mul_n($re, $re), nqp::mul_n($im, $im)));
nqp::want(nqp::p6box_n($res), 'Nn', $res);
}

multi sub infix:<+>(Complex:D \$a, Complex:D \$b) {
my $new := nqp::create(Complex);
nqp::bindattr_n( $new, Complex, '$!re',
Expand Down

0 comments on commit aa1ea2a

Please sign in to comment.