The result of the values โof A and B is as follows.
Asked
Active
Viewed 111 times
-4
-
The reason is implicit integer promotion. There are many similar questions all over SO. Study the linked duplicate. โ Lundin Dec 20 '17 at 10:38
1 Answers
0
In the first case, the type of the expression on the right-hand side is int
, and the value is -121. In the second case, the type is uint32_t
, and the value is uint32_t(-121) == 4294967175
. The latter cannot be precisely represented in a float
, so it gets rounded.

Igor Tandetnik
- 50,461
- 4
- 56
- 85
-
1I think the subtlety here is that while `uint8_t` is an unsigned type, when used as the left operand of a shift operation, it gets promoted to `int`, not `unsigned int`. The result of the last signed left shift results in a negative `int` value (and technically, I believe the sign change qualifies as overflow), which remains negative when converted to `float`. โ Tom Karzes Dec 20 '17 at 02:00