The Wayback Machine - https://web.archive.org/web/20221231172036/https://github.com/golang/go/pull/57494
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

math: handle int64 overflows for odd integer exponents in Pow(-0, y) #57494

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dop251
Copy link

@dop251 dop251 commented Dec 28, 2022

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

…in Pow(-0, y)

The existing implementation does a float64 to int64 comversion 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 golang#57465
@gopherbot
Copy link

gopherbot commented Dec 28, 2022

This PR (HEAD: 9a6d458) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/459815 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

gopherbot commented Dec 28, 2022

Message from Keith Randall:

Patch Set 1:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/459815.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

gopherbot commented Dec 28, 2022

This PR (HEAD: 3bfbd85) has been imported to Gerrit for code review.

Please visit https://go-review.googlesource.com/c/go/+/459815 to see it.

Tip: You can toggle comments from me using the comments slash command (e.g. /comments off)
See the Wiki page for more info

@gopherbot
Copy link

gopherbot commented Dec 28, 2022

Message from Dmitry Panov:

Patch Set 2:

(3 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/459815.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link

gopherbot commented Dec 28, 2022

Message from Keith Randall:

Patch Set 2: Code-Review+2 TryBot-Bypass+1

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/459815.
After addressing review feedback, remember to publish your drafts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

math: Pow(negativeZero, number_that_overflows_int64) produces incorrect result on arm64
2 participants