-
Notifications
You must be signed in to change notification settings - Fork 1.7k
casting integer literal to float is unnecessary #3877
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
Conversation
tests/ui/cast_size.stderr
Outdated
|
||
error: casting usize to f64 causes a loss of precision on targets with 64-bit wide pointers (usize is 64 bits wide, but f64's mantissa is only 52 bits wide) | ||
error: casting integer literal to f64 is unnecessary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning shouldn't change, as for example 9999999999999999_usize != 9999999999999999_f64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is.
But 9999999999999999_usize as f64 == 9999999999999999_f64, so the suggestion equal to orgin code.
Maybe we should check mantissa bits wide for integer literal case.
Then add the test case mentioned above.
Is it ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should rewrite some test case.
The error type doesn't match name of test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed some test case to keep original error type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
9999999999999999_usize as f64 == 9999999999999999_f64
That is correct, but the previous warning explicitly warns you about this kind of cast, since you lose precision with it. The new suggestion would indicate to the programmer, that this cast is always ok and he can change the code.
For the purpose of easier reviewing: Could you add new commits for a change and avoid force pushing? You can then squash the commits later |
I think this looks good now, but I have to take a closer look at it this evening. |
Thanks! @bors r+ |
📌 Commit d9dd008 has been approved by |
casting integer literal to float is unnecessary fix issue #3842
☀️ Test successful - checks-travis, status-appveyor |
fix issue #3842