go/src/math
Dmitry Panov 7f9ee2ba5b math: handle int64 overflows for odd integer exponents in Pow(-0, y)
The existing implementation does a float64 to int64 conversion in order to check whether the number is odd, however it does not check for overflows. If an overflow occurs, the result is implementation-defined and while it happens to work on amd64 and i386, it produces an incorrect result on arm64 and possibly other architectures.

This change fixes that and also avoids calling isOddInt altogether if the base is +0, because it's unnecessary.

(I was considering avoiding the extra check if runtime.GOARCH is "amd64" or "i386", but I can't see this pattern being used anywhere outside the tests. And having separate files with build tags just for isOddInt() seems like an overkill)

Fixes #57465

Change-Id: Ieb243796194412aa6b98fac05fd19766ca2413ef
GitHub-Last-Rev: 3bfbd85c4c
GitHub-Pull-Request: golang/go#57494
Reviewed-on: https://go-review.googlesource.com/c/go/+/459815
Auto-Submit: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Bypass: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
2023-01-24 19:10:58 +00:00
..
big math/big: validate result of Float.GobDecode 2023-01-23 18:18:05 +00:00
bits math/bits: directly calculate quo/rem when hi is zero in Div64 2022-11-14 05:09:39 +00:00
cmplx all: add missing periods in comments 2022-11-18 17:59:44 +00:00
rand internal/godebug: export non-default-behavior counters in runtime/metrics 2023-01-19 22:26:43 +00:00
abs.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
acos_s390x.s
acosh.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
acosh_s390x.s
all_test.go math: handle int64 overflows for odd integer exponents in Pow(-0, y) 2023-01-24 19:10:58 +00:00
arith_s390x.go math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
arith_s390x_test.go
asin.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
asin_s390x.s
asinh.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
asinh_s390x.s
atan.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
atan2.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
atan2_s390x.s
atan_s390x.s
atanh.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
atanh_s390x.s
bits.go all: replace `` and '' with “ (U+201C) and ” (U+201D) in doc comments 2022-04-05 17:52:29 +00:00
cbrt.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
cbrt_s390x.s
const.go math: show value of integer constants in comments 2022-09-21 14:07:39 +00:00
const_test.go math: add MaxUint, MinInt, MaxInt 2021-05-03 22:44:33 +00:00
copysign.go math: improve documentation of Copysign 2022-04-14 17:42:53 +00:00
cosh_s390x.s
dim.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
dim_amd64.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
dim_arm64.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
dim_asm.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
dim_noasm.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
dim_riscv64.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
dim_s390x.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
erf.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
erf_s390x.s
erfc_s390x.s
erfinv.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
example_test.go math: add Remainder example 2021-10-07 18:09:53 +00:00
exp.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
exp2_asm.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
exp2_noasm.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
exp_amd64.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
exp_amd64.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
exp_arm64.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
exp_asm.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
exp_noasm.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
exp_s390x.s
expm1.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
expm1_s390x.s
export_s390x_test.go
export_test.go
floor.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
floor_386.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
floor_amd64.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
floor_arm64.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
floor_asm.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
floor_noasm.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
floor_ppc64x.s all: add //go:build lines to assembly files 2021-05-13 09:12:17 +00:00
floor_s390x.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
floor_wasm.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
fma.go
frexp.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
gamma.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
huge_test.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
hypot.go math: optimize Hypot function 2022-10-01 01:51:35 +00:00
hypot_386.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
hypot_amd64.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
hypot_asm.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
hypot_noasm.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
j0.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
j1.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
jn.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
ldexp.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
lgamma.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
log.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
log1p.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
log1p_s390x.s
log10.go math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
log10_s390x.s
log_amd64.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
log_asm.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
log_s390x.s
log_stub.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
logb.go math: fix function name in comment 2022-11-07 19:46:45 +00:00
mod.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
modf.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
modf_arm64.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
modf_asm.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
modf_noasm.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
modf_ppc64x.s all: add //go:build lines to assembly files 2021-05-13 09:12:17 +00:00
nextafter.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
pow.go math: handle int64 overflows for odd integer exponents in Pow(-0, y) 2023-01-24 19:10:58 +00:00
pow10.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
pow_s390x.s
remainder.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
signbit.go
sin.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
sin_s390x.s
sincos.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
sinh.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
sinh_s390x.s all: fix typos 2021-08-17 13:54:10 +00:00
sqrt.go cmd/compile,math: remove all sqrt assembly code 2022-08-15 17:07:57 +00:00
stubs.go all: go fix -fix=buildtag std cmd (except for bootstrap deps, vendor) 2021-10-28 18:17:57 +00:00
stubs_s390x.s math: avoid assembly stubs 2021-04-15 15:48:19 +00:00
tan.go all: fix some lint issues 2022-05-08 17:27:54 +00:00
tan_s390x.s all: fix typos 2021-08-17 13:54:10 +00:00
tanh.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
tanh_s390x.s
trig_reduce.go all: gofmt main repo 2022-04-11 16:34:30 +00:00
unsafe.go