4 ms·
I'm new to learning C. What exactly is the problem with uint32_t my_int = (uint32_t)my_float?
by engeljohnb 3y ago
I'm new to learning C. What exactly is the problem with
uint32_t my_int = (uint32_t)my_float?
- yvdriess 3y agoThat is not a problem, it simply converts the float value to uint32. What the post mentions is `uint32_t my_int = (uint32_t)&my_float;`
- gpderetta 3y agoThat's a different problem: that simply convert a pointer to float to an uint32 (probably truncating it). What the post mentions is 'uint32_t my_int = *(uint32_t*)&my_float; (Of course you had it right, and HN ate your formatting, but it is funnier this way)
- anonymoushn 3y agoThat does a different thing. It converts the actual number represented by the float to an integer. We want to get an integer that contains the same bit pattern as the float.