diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:23:02 +0200 |
---|---|---|
committer | Michael Stapelberg <stapelberg@debian.org> | 2014-06-19 09:23:02 +0200 |
commit | 8fcc691d6fa80c9ddf38bf0d34b803bab0e421d5 (patch) | |
tree | ba71646a10b518372d110532d86fcf0b98edc14f /src/pkg/math/cmplx/pow.go | |
parent | 3bb719bbf3cdb97b3901f3baaa2da9d02a5c3cdb (diff) | |
parent | 8a39ee361feb9bf46d728ff1ba4f07ca1d9610b1 (diff) | |
download | golang-8fcc691d6fa80c9ddf38bf0d34b803bab0e421d5.tar.gz |
Merge tag 'upstream/1.3' into debian-sid
Upstream version 1.3
Diffstat (limited to 'src/pkg/math/cmplx/pow.go')
-rw-r--r-- | src/pkg/math/cmplx/pow.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/pkg/math/cmplx/pow.go b/src/pkg/math/cmplx/pow.go index 4dbc58398..1630b879b 100644 --- a/src/pkg/math/cmplx/pow.go +++ b/src/pkg/math/cmplx/pow.go @@ -43,7 +43,25 @@ import "math" // IEEE -10,+10 30000 9.4e-15 1.5e-15 // Pow returns x**y, the base-x exponential of y. +// For generalized compatibility with math.Pow: +// Pow(0, ±0) returns 1+0i +// Pow(0, c) for real(c)<0 returns Inf+0i if imag(c) is zero, otherwise Inf+Inf i. func Pow(x, y complex128) complex128 { + if x == 0 { // Guaranteed also true for x == -0. + r, i := real(y), imag(y) + switch { + case r == 0: + return 1 + case r < 0: + if i == 0 { + return complex(math.Inf(1), 0) + } + return Inf() + case r > 0: + return 0 + } + panic("not reached") + } modulus := Abs(x) if modulus == 0 { return complex(0, 0) |