-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SIL Diagnostics] Warn when assigning an integer literal to a variable of floating-point type results in loss of precision. #17274
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
The warnings are disabled when the conversion happens through explicit constructor call. E.g.
|
@swift-ci please smoke test |
Would it be more clear if we tell the user what value actually results? Maybe something along the lines of: "Warning: '16777217' is not exactly representable as 'Float'; 'f3' has value '16777216'. |
b0336ea
to
43131b4
Compare
@swift-ci please smoke test |
@stephentyrone Sounds good to me. I have pushed a commit that prints the new value in the warning messages. E.g. $ let f3: Float = 16777217 |
Nice! If you update the PR with conflicts resolved, I can review later today or tomorrow. |
// 2^128 * (2^25-1)/2^25 | ||
var _ /*float32_max*/ : Float32 = (340282346638528859811704183484516925440) // in hexfloat = 0x1.fffffep127 | ||
|
||
var _ /*float32_near_max_but_imprecise*/ : Float32 = (340282326356119256160033759537265639425) // expected-warning {{'340282326356119256160033759537265639425' is not exactly representable as 'Float32' (aka 'Float'); it becomes '3.40282326E+38'}} |
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.
We probably want to be printing these with full precision, to make it clear what the difference is.
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.
@jrose-apple Yeah sure, let me make that change.
43131b4
to
2ff9d27
Compare
@swift-ci please smoke test |
@jrose-apple Done. Now the new float value is displayed like an integer to make the imprecision obvious E.g. @stephentyrone I have fixed the merged conflicts. Thanks for your help with this. |
@swift-ci please smoke test |
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.
LGTM, thanks!
@swift-ci please test and merge |
variable of floating-point type results in loss of precision. <rdar://15224041>
2ff9d27
to
193407b
Compare
@swift-ci please test and merge |
1 similar comment
@swift-ci please test and merge |
This feature was requested in the radar issue: rdar://15224041.