-
-
Notifications
You must be signed in to change notification settings - Fork 5.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
Implement proper print_shortest for Float16 #5959
Comments
This is not so simple: the shortest number of digits to reconstruct a value of a floating-point type depends not only on the value but also the type to be reconstructed. We could easily print the shortest number of digits that would be required to reproduce the same value as a Float32, but it might have well more than five digits even though you never need more than five digits to reconstruct a particular Float16. There are only two reasonable solutions that I can think of:
I kind of favor the latter as a project. It would be nice to have support for optimal printing in arbitrary bases and arbitrary precisions. |
I'm going to assign myself here. I've meandered through the double-conversion library before and even started a port at one point. I think it'd be great to have a more Julian implementation of the algorithm |
Just curious, are there any functions like |
|
Alright, made some progress on this. Feel free to check out https://github.com/quinnj/Grisu.jl. It's currently passing the couple hundred thousand tests for the individual |
Sweet! That sounds great. I'll have to check it out tomorrow. |
After #5948
Float16
prints 5 significant digits, to ensure that every printedFloat16
value parses back to the same value. This fix is not in line with how we printFloat32
andFloat64
and the documentation forprint_shortest
, and I think this would make a nice "up-for-graps" issue.There might be a reason to explicitly show the horrible precision for
Float16
by default, butprint_shortest
should give the documented answer.The text was updated successfully, but these errors were encountered: