{NaN(), 1},
{NaN(), Pi},
{NaN(), NaN()},
+
+ // Issue #7394 overflow checks
+ {2, float64(1 << 32)},
+ {2, -float64(1 << 32)},
+ {-2, float64(1<<32 + 1)},
+ {1 / 2, float64(1 << 45)},
+ {1 / 2, -float64(1 << 45)},
+ {Nextafter(1, 2), float64(1 << 63)},
+ {Nextafter(1, -2), float64(1 << 63)},
+ {Nextafter(-1, 2), float64(1 << 63)},
+ {Nextafter(-1, -2), float64(1 << 63)},
}
var powSC = []float64{
0, // pow(-Inf, -Pi)
NaN(), // pow(NaN, 1)
NaN(), // pow(NaN, +Pi)
NaN(), // pow(NaN, NaN)
+
+ // Issue #7394 overflow checks
+ Inf(1), // pow(2, float64(1 << 32))
+ 0, // pow(2, -float64(1 << 32))
+ Inf(-1), // pow(-2, float64(1<<32 + 1))
+ 0, // pow(1/2, float64(1 << 45))
+ Inf(1), // pow(1/2, -float64(1 << 45))
+ Inf(1), // pow(Nextafter(1, 2), float64(1 << 63))
+ 0, // pow(Nextafter(1, -2), float64(1 << 63))
+ 0, // pow(Nextafter(-1, 2), float64(1 << 63))
+ Inf(1), // pow(Nextafter(-1, -2), float64(1 << 63))
}
var vfpow10SC = []int{
return NaN()
}
if yi >= 1<<63 {
- return Exp(y * Log(x))
+ // yi is a large even int that will lead to overflow (or underflow to 0)
+ // for all x except -1 (x == 1 was handled earlier)
+ switch {
+ case x == -1:
+ return 1
+ case (Abs(x) < 1) == (y > 0):
+ return 0
+ default:
+ return Inf(1)
+ }
}
// ans = a1 * 2**ae (= 1 for now).
// accumulate powers of two into exp.
x1, xe := Frexp(x)
for i := int64(yi); i != 0; i >>= 1 {
+ if xe < -1<<12 || 1<<12 < xe {
+ // catch xe before it overflows the left shift below
+ // Since i !=0 it has at least one bit still set, so ae will accumulate xe
+ // on at least one more iteration, ae += xe is a lower bound on ae
+ // the lower bound on ae exceeds the size of a float64 exp
+ // so the final call to Ldexp will produce under/overflow (0/Inf)
+ ae += xe
+ break
+ }
if i&1 == 1 {
a1 *= x1
ae += xe