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

NRF_LOG_FLOAT doesn't display negative numbers properly

Platform: nRF52832 using SDK12.2 and Keil 5.20a

I've encountered strange corner case when displaying negative floats using NRF_LOG_DEBUG.

My test code looks like this:

float test_float=-0.99701f;

//use sprintf as reference point
char buff[50];
sprintf(buff, "sprintf: %f",test_float);

NRF_LOG_RAW_DEBUG("NRF_LOG_FLOAT:" NRF_LOG_FLOAT_MARKER " %s\r\n", NRF_LOG_FLOAT(test_float),nrf_log_push(buff));

This gives following output: NRF_LOG_FLOAT:0.99 sprintf: -0.997010. As you can see sprintf displays correct value, NRF_LOG_FLOAT forgets minus sign. This happens for float values in range (0,-1).

Is this a bug in SDK or am I forgetting something in my code?

Related