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 Reply Children
  • Hi Jowi, 

    altering the Code > Printf/Scanf > Printf Floating Point Supported from Float to Double in the Project settings removes the assert. However, then I guess the FPU might not be used at all. 

    I must admit that im not quite sure why you're getting an FPU exception, but could it be because 1.712e38 is larger than 2^+127, i.e. ~1.701,411,83 x10^+38 which is the largest signed number that can be represented?

    We have added the assert here to notify the uses about FPU, but you can remove the assert if you know that its OK to ignore it. 

            /*
             * The last chance to indicate an error in FPU to the user 
             * as the FPSCR is now cleared
             *
             * This assert is related to previous FPU operations 
             * and not power management.
             *
             * Critical FPU exceptions signaled:
             * - IOC - Invalid Operation cumulative exception bit.
             * - DZC - Division by Zero cumulative exception bit.
             * - OFC - Overflow cumulative exception bit.
             */
            ASSERT((original_fpscr & 0x7) == 0);

    Best regards

    Bjørn

Related