[PATCH] D64666: [Sema] Enable -Wimplicit-int-float-conversion for integral to floating point precision loss
Ziang Wan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 4 12:02:44 PDT 2019
ziangwan added a comment.
In D64666#1613356 <https://reviews.llvm.org/D64666#1613356>, @mgorny wrote:
> In D64666#1613057 <https://reviews.llvm.org/D64666#1613057>, @ziangwan wrote:
> > The warning is actually correct here. This implicit integral to float conversion loses precision. Is it the intended behavior of the code? If so, we can simply add an explicit type cast to silence the warning.
> I don't really know. Hence, I added author of the code and libc++ maintainers as subscribers. Do you think I should open a bug for it too?
We can wait for libc++ maintainers to respond before we open a bug.
Here is more insight of this warning:
float a = unsigned int::max() - unsigned int::min() + float(1);
The `max() - min()` expression evaluates to 2147483645 as type unsigned int. It then gets converted to float type, loses precision and becomes 2147483648f, where the significand is all 1. Then, 1f is added to 2147483648f. The final value is 2147483648f because 1 is too small compared to 2147483648f and has no effect.
I don't know if the above is the intended behavior. Eventually, the final value is a floating point type with significand all ones. I guess that's what the author wants after all.
CHANGES SINCE LAST ACTION
More information about the cfe-commits