Skip to content

Commit

Permalink
Fix Complex exponentiation involving zeros
Browse files Browse the repository at this point in the history
Use the same rules as other numerics: 0**n == 0, but 0**0 == 1

Fixes RT#128785: https://rt.perl.org/Ticket/Display.html?id=128785
  • Loading branch information
zoffixznet committed Nov 17, 2016
1 parent 85c7072 commit 7f32243
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/core/Complex.pm
Expand Up @@ -422,13 +422,23 @@ multi sub infix:</>(Real \a, Complex:D \b) returns Complex:D {
}

multi sub infix:<**>(Complex:D \a, Complex:D \b) returns Complex:D {
(a.re == 0e0 && a.im == 0e0) ?? Complex.new(0e0, 0e0) !! (b * a.log).exp
(a.re == 0e0 && a.im == 0e0)
?? ( b.re == 0e0 && b.im == 0e0
?? Complex.new(1e0, 0e0)
!! Complex.new(0e0, 0e0)
)
!! (b * a.log).exp
}
multi sub infix:<**>(Num(Real) \a, Complex:D \b) returns Complex:D {
a == 0e0 ?? Complex.new(0e0, 0e0) !! (b * a.log).exp
a == 0e0
?? ( b.re == 0e0 && b.im == 0e0
?? Complex.new(1e0, 0e0)
!! Complex.new(0e0, 0e0)
)
!! (b * a.log).exp
}
multi sub infix:<**>(Complex:D \a, Num(Real) \b) returns Complex:D {
(b * a.log).exp
b == 0e0 ?? Complex.new(1e0, 0e0) !! (b * a.log).exp
}

multi sub infix:<==>(Complex:D \a, Complex:D \b) returns Bool:D { a.re == b.re && a.im == b.im }
Expand Down

0 comments on commit 7f32243

Please sign in to comment.