AnsweredAssumed Answered

PRINTF problem in SDK 2.0

Question asked by reg exp on Jun 19, 2016
Latest reply on Jun 21, 2016 by Iva Susnova

Hello,

 

I have FRDM-K64F, KDS 3.2 and SDK 2.0 for K64F CPU family.

 

When I startet to use SDK 2.0 I found two problem with PRINTF. One less serious is definition of its first parameters "char *", which should be nowadays "const char *". It generates enormous number of warnings.

 

The second more serious problem is bug of float numbers output. Below is my main():

int main(void) {

  /* Init board hardware. */

  BOARD_InitPins();

  BOARD_BootClockRUN();

  BOARD_InitDebugConsole();

 

  float x = 0.9;

  printf( "%f %f %f\n", x, x - 1.0, -3.14 );

  PRINTF( "%f %f %f\n", x, x - 1.0, -3.14 );

 

  /* Add your code here */

  for(;;) { /* Infinite loop to avoid leaving the main function */

    __asm("NOP"); /* something to use as a breakpoint stop while looping */

  }

}

 

The output is:

0.900000 -0.100000 -3.140000

0.900000 -1.100000 -4.140000

 

The problem is in function DbgConsole_ConvertFloatRadixNumToString where some programmer badly implements condition:

if (fa <= pow(-10, precision_width))

        {

            intpart--;

        }

The sign minus must be in front of pow.

 

reg.

Outcomes