]> Cypherpunks repositories - gostls13.git/commitdiff
math/cmplx: avoid panic in Pow(x, NaN())
authorBryan C. Mills <bcmills@google.com>
Tue, 5 Feb 2019 15:22:32 +0000 (10:22 -0500)
committerBryan C. Mills <bcmills@google.com>
Wed, 27 Feb 2019 14:01:03 +0000 (14:01 +0000)
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>
src/math/cmplx/cmath_test.go
src/math/cmplx/pow.go

index 80c3b33937e2aa5045bf8879ec528fbba04ce141..fbb49fdd5bca7c118ecc7e0533855e375e997841 100644 (file)
@@ -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 {
index 1630b879b88b0dbc97c4d5ef16a1815f40c66953..5a405f8e9607f0961da2c62669ec9af3b813254b 100644 (file)
@@ -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: