https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70523
Bug ID: 70523 Summary: Inconsistent casting of floats to unsigned short Product: gcc Version: 4.8.4 Status: UNCONFIRMED Severity: minor Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: sergey.s at samsung dot com Target Milestone: --- Created attachment 38171 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38171&action=edit Test program Casting of float expression to unsigned short gives different result when cast is performed via intermediate variable. Specifically: #include <stdio.h> int main() { float f = 1.7857142687f; printf("%.10f\n", f); unsigned short b = 28; unsigned short a = (unsigned short)(b * f); printf("%u\n", a); float temp = b * f; a = (unsigned short)temp; printf("%u\n", a); return 0; } Output: 1.7857142687 49 50 Reproduced only for 32-bit compilation. On 64-bit compilers both outputs are 50. Optimization level shall be default. If optimization level is -O2 or higher both outputs are 50. Similar to bug 47297, but here value of float expression is well within range of unsigned short, so behaviour should be defined.