-
Notifications
You must be signed in to change notification settings - Fork 18k
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
strconv: ParseFloat does not accept a leading sign on nan #73163
Comments
See IEEE 754 (2008) or (2019).
The optional preceding sign is valid in C ( #include <math.h>
#include <stdio.h>
#include <stdlib.h>
int
main(int argc, char *argv[]) {
if (argc < 2) return 100;
double v = strtod(argv[1], NULL);
printf("%g\n", v);
if (isnan(v)) printf("is nan\n");
return 0;
}
...and CPython.
|
We first noticed this problem when our Prometheus servers began rejecting scrapes from a C++ workload that inadvertently divided by zero. I guess you could say it can cause interop issues. |
Change https://go.dev/cl/662815 mentions this issue: |
Parse float is specified to not take a signed nan.
The "(possibly signed)" part does not apply to NaN. So this is working as intended. I will close the issue. Sign on a NaN is a weird thing to want. And there's no way to parse a NaN payload, so you can't round-trip a NaN through print/parse anyway. |
@randall77, yes, I am saying the Go specification contradicts IEEE 754 -- and is contrary to what users expect. Is this not a bug? I will quote the relevant section again. IEEE 754 (2008) or (2019):
separately
Yes. But, as noted above, when the rest of the world supports signs on the character sequence encoding of a NaN, it leads to unnecessary interop problems when people try to use Go. |
If we were implementing |
Question about a pull quote from that:
To which specification does this refer? The IEEE specification? The go float specification?
The Would not "compliance with the IEEE specification" be a really good reason? If someone has actually written a program that depends on the current behaviour, I'd love to hear about it. Otherwise, in the interests of interoperability, it's probably best to fix it. |
In this case the specification is the godoc for And just because we reserve the right, doesn't mean we will exercise that right.
If
But it never says "we incorporate the whole of IEEE 754 by reference" or anything like that.
I think that argument works in both directions. Who is depending on Java is happy to accept |
Go version
go version go1.24.1 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
https://go.dev/play/p/6sYtMAxqdFj
What did you see happen?
What did you expect to see?
The text was updated successfully, but these errors were encountered: