-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
regression caused by PR #13276: echo 0.6 show 0.59999999999999998, unlike all other languages #13362
Comments
$0.6
is now 0.59999999999999998
The amount of research you did for this regression issue is amazing! 👏 |
[0.10000000000000001,0.20000000000000001,0.29999999999999999,0.40000000000000002,0.5,0.59999999999999998,0.69999999999999996,0.80000000000000004,0.90000000000000002]
Correction, this will blow up size for json, if the value comes from a handwritten decimal number. To my experience the majority of json number data doesn't come from floating point numbers entered manually in decimal.
True. And I am sorry for that. Regarding the output of regarding #include <math.h>
#include <stdio.h>
int main() {
double f = 0.1;
for(int i = 0; i < 100; ++i) {
printf("%g\n", f);
f = nextafter(f, 100);
}
} output: only #include <cmath>
#include <iostream>
using namespace std;
int main() {
double f = 0.1;
for(int i = 0; i < 100; ++i) {
cout << f << endl;
f = nextafter(f, 100);
}
} |
beginners need to learn about FP semantics. Just like in any language.
there's no roundtrip here. A language's default
since #13276 has been reverted, I'm gonna close this issue; followup work is to implement #13365 |
That works best if the language is honest about FP
Whatever... |
the recently merged printing float values will have one more digit. #13276 introduced the regression /cc @krux02
that PR commented out some tests and changed some numbers for preexisting tests in tests/system/tostring.nim to deal with the fact that numbers now print weirdly; this will likely break other people's tests in the wild
pretty much no other language I know of does that, and for good reason:
python, D, C, C++, go, node js, matlab, octave, java...
yet they can handle serialization/deserialization roundtrip just fine, and aren't any less correct; printing 0.6 as 0.6 does not imply any less precision !
Example
Current Output
Expected Output
Additional Information
that PR aimed to fix #13196 but IMO there should be a better fix that doesn't introduce this regression. EDIT: indeed, see #13364
Indeed, other languages I've tried don't have that serialization/deserialization round-trip issue;
and pretty much all languages I'm familiar with print float literals like 0.4 as simply 0.4 (using default printing command):
consequences
this may break other people's tests that relied on stringifications of simple looking numbers like
echo (0.4, "foo")
this will blow up size of json files which impacts performance etc
now shows:
shows as:
now prints:
proposal
The text was updated successfully, but these errors were encountered: