-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Inexact and/or Wrong {From,To}Primitive
#10481
Comments
This appears to just be floating point precision, although (python3): >>> int(float(1000000000000002345))
1000000000000002304 so we're not doing the best job possible. (Personally, I'd think that returning The others are concerning though. |
Also,
Is likely because the result is undefined if the value doesn't fit in result type (and clearly 42.5e80 doesn't fit in a u8 or i32).
docs: float → unsigned, float → signed |
@huonw I agree that the strict exactness would make the methods less useful, but this fact itself should be documented somehow. (Or, if we are extra careful about this issue, we can add |
Yep, I definitely agree that they should be bounds-checked, I'd guess that it was just @erickt overlooking the float conversions. |
As @thestinger pointed out, undefined results -- particularly of |
Nominating. |
We need |
pcwalton recommends we adopt an approach of implementing the equivalent of:
|
Accepted for P-high; it is a potential (though at least known) soundness hole, and thus a security bug. But we are permitted to still leave such things for post 1.0 (they are just still high priority in that context). |
It appears that to support I'm unsure of whether we'd want to do this in all arithmetic, though, or only in some cases. |
Visiting for triage, still relevant. |
Luckily |
The last of these is just a duplicate of #10184, the others are expected behaviour. |
Add `allow_attribute` lint Fixes rust-lang#10468 changelog: new lint: [`allow_attributes`] [rust-lang#10481](rust-lang/rust-clippy#10481)
Motivating examples:
Note that the last two results can change depending on your optimization level. (Is it another issue?) It seems that it's due to the constant propagation across inlined function calls.
Currently we check for such cases in int to int and float to float conversion, but we don't check (and solely rely on casting) in int to float and float to int conversion. This can cause the inexact computation in two ways: unwanted truncation, and failed bound check. Four possible decisions have their pros and cons respectively, but should be decided and documented.
The text was updated successfully, but these errors were encountered: