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: Pow(NaN, 0) returns an incorrect value #66338
Comments
feel free to submit a CL/PR |
This behavior is correct given the special cases listed in the docs for |
How behavior can be correct if there is one result in the function's comments and docs and another result in fact? Either the comments and documentation are lying or this case is being handled incorrectly. Please write why this is correct behavior, given that doc and the |
Read the doc comment carefully.
Note the "in order", and the fact that the first one matches the input described. I don't know whether we diverge from IEEE 754 or not, but even if we did this is certainly a weird enough case that it doesn't warrant making a backwards-incompatible change to the spec and behavior. |
From IEEE 754 2008:
|
Go version
go version go1.22.1 linux/amd64
Output of
go env
in your module/workspace:What did you do?
I'm trying to take:
https://go.dev/play/p/OdD0TalqBrN
What did you see happen?
I see output:
What did you expect to see?
The comments to the
Pow
function give examples of return values:go/src/math/pow.go
Lines 31 to 32 in db6097f
The result should be as in the comments or it should return
1 1
as it does in theIEEE Std. 754-2008 "Section 9.2.1 Special values"
. Either way it seems to me that these two edge cases should return the same value.It's probably due to a case order problem:
go/src/math/pow.go
Lines 55 to 62 in db6097f
This example should handle the case on line 61. But due to a higher-priority case on line 57 an incorrect value is returned.
I think it would be more correct to move a case with NaN checks to the begin or move all edge cases at the beginning of the
pow
function fromswitch-case
toif
statement like this:The text was updated successfully, but these errors were encountered: