-
Notifications
You must be signed in to change notification settings - Fork 13.3k
{f32,f64}::DIGITS is misleading #89106
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
Comments
This is interesting. To give a concrete example, the print out in the
That's just one example of a pair of adjacent f32s that needs 9 digits of precision to differentiate. They do seem to be on the rarer side. I would kinda support changing the DIGITS constant to the upper bound. If the current constants are left it, it might be kinda neat to tell users approximately what percentage of the time digits is too low. |
Similar issue #88734 |
This constant doesn't seem to be used a lot. Grepping through the latest version of all crates on crates.io for
(Almost all of these use the deprecated one in We should probably just deprecate (Also why is |
A few more that weren't matched by my regex:
|
|
The linked clippy code looks suspicious in at least one particular way: it doesn't literally parse both the original and the proposed replacement, into the appropriate type, to do a bitwise comparison. It only parses the original and the only obviously-exact operation is For a (Also it should parse with both |
While they come with a caveat that they are an "approximate" value, these constants are treated as gospel and invoked by clippy in the excessive_precision lint to create a warning.
Clippy is wrong, however, in doing so.The numbers currently embedded in these constants reflect the lower bound, beyond which precision cannot be certain.A binary32 may, however, contain up to 9 significant decimal digits, a binary64 may contain up to 17 decimal digits, and it is these numbers that are recommended as minimums for printing decimal strings if one wants to assure it will be parsed back as the actual value. In other words, there is a range. These const values have lead people to misleading conclusions, the correct answer to which cannot even be inferred from the documentation since there is no specification on how they are "approximate".
Either these constants should reflect the upper bound of precision, another constant should be embedded alongside them reflecting the other side of the bound and the documentation should discuss both ends of the range, or they should be deprecated wholesale.
EDIT: I misunderstood a segment of the code and Clippy's is a touch less problematic than I thought. Alas, precisely because of even more confusing naming from confusing names...
The text was updated successfully, but these errors were encountered: