mirror of
https://github.com/golang/go
synced 2024-11-23 20:30:04 -07:00
math/cmplx: avoid panic in Pow(x, NaN())
Fixes #30088 Change-Id: I08cec17feddc86bd08532e6b135807e3c8f4c1b2 Reviewed-on: https://go-review.googlesource.com/c/161197 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
4a9aba5afe
commit
bd98628676
@ -400,9 +400,11 @@ var polarSC = []ff{
|
||||
}
|
||||
var vcPowSC = [][2]complex128{
|
||||
{NaN(), NaN()},
|
||||
{0, NaN()},
|
||||
}
|
||||
var powSC = []complex128{
|
||||
NaN(),
|
||||
NaN(),
|
||||
}
|
||||
var vcSinSC = []complex128{
|
||||
NaN(),
|
||||
@ -734,8 +736,8 @@ func TestPow(t *testing.T) {
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(vcPowSC); i++ {
|
||||
if f := Pow(vcPowSC[i][0], vcPowSC[i][0]); !cAlike(powSC[i], f) {
|
||||
t.Errorf("Pow(%g, %g) = %g, want %g", vcPowSC[i][0], vcPowSC[i][0], f, powSC[i])
|
||||
if f := Pow(vcPowSC[i][0], vcPowSC[i][1]); !cAlike(powSC[i], f) {
|
||||
t.Errorf("Pow(%g, %g) = %g, want %g", vcPowSC[i][0], vcPowSC[i][1], f, powSC[i])
|
||||
}
|
||||
}
|
||||
for _, pt := range branchPoints {
|
||||
|
@ -48,6 +48,9 @@ import "math"
|
||||
// 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.
|
||||
if IsNaN(y) {
|
||||
return NaN()
|
||||
}
|
||||
r, i := real(y), imag(y)
|
||||
switch {
|
||||
case r == 0:
|
||||
|
Loading…
Reference in New Issue
Block a user