This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

FPU Error on printf() for "%g" for large numbers

Hello,

I am porting a software to the nRF52 SDK16.0 . This software uses Floating Point numbers with Exponent-Byte=0x7F to signal Error conditions (then treated as unsigned ints with 24 bits).

However, these values are still numbers. Like 

hk_hum.floatval = 1.71141e38   ( = 0x7F 00 XX XX == ERROR XXXX) 

But if printf has printed the number (which is OK), the nrf_pwr_mgmt.c trigger this assert (line 125):

...

hk_hum.floatval = 1.71141e38; // Force Error
tb_printf("H:%g\n",hk_hum.floatval); // Output is H:1.71141e38

. . .

ASSERT((original_fpscr & 0x7) == 0);  // in nrf_pwr_mgmt.c

...

Best regards,
Jo

Parents
  • Floats are AFAIK promoted to double for variable argument functions, and the optimzier might just put the (compile time constant) value directly into the tb_printf() call - either on the stack or into FPU registers.

    You might need to look at the generated assembly code here - the FPU exception flag could be generated further down when actually using hk_hum.floatval (or writing it into memory).

Reply
  • Floats are AFAIK promoted to double for variable argument functions, and the optimzier might just put the (compile time constant) value directly into the tb_printf() call - either on the stack or into FPU registers.

    You might need to look at the generated assembly code here - the FPU exception flag could be generated further down when actually using hk_hum.floatval (or writing it into memory).

Children
No Data
Related