The type of the conditional expression x ? a : b
is the common type of the types of the expressions a
and b
. The common type of uint32_t
and float
is... float
. Whichever of the two operands is evaluated, its value is converted to the common type, and that's the value of the conditional expression.
Your number 470698344
is 29 bits long, but your float
can only 24 bits of precision. So in the conversion, precision is lost. When the value of the conditional expression is assigned to r
, this less-precise floating point value is truncated to an integer, which is different from 470698344
.