I am trying to understand how floating point numbers are represented on thingy 53, using the code below.
#include "stdint.h" #include "stdio.h" typedef union variable_t { float val_float; uint32_t val_uint32; }variable; #define MAIN_LOG_MODULE_NAME app LOG_MODULE_REGISTER(MAIN_LOG_MODULE_NAME); #define SLEEP_INTERVAL_MS 1000 int main(void) { variable a_variable; a_variable.val_float = 2.25f; for (;;) { // a_variable.val_float += 0.125; LOG_INF("%f \n",a_variable.val_float); printf("%f \n",a_variable.val_float); LOG_INF("%d \n",a_variable.val_uint32); k_sleep(K_MSEC(SLEEP_INTERVAL_MS)); } }
When I look at the console here is the output:
My first question is why can't I see the float value?
Second and main question, how is the floating point value encoded.
If I look at the binary representation of the decimal value I calculate it to be:
0100 0000 0001 0000 0000 0000 0000 0000
I would expect to see 1001 somewhere in order to display the value 2.25?