Why my PRINTF cannot prints values greater than 2147483647?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Why my PRINTF cannot prints values greater than 2147483647?

1,484 次查看
vivienl
Contributor I

Hi,

I'm trying to print a double value greater than 2147483647 but the output is always display 2147483647.0000000000 on the terminal. Can someone helps me to solve this issue?

This is my code:

pastedImage_4.png

The results are:

pastedImage_5.png

From the debug window I can see the value val is greater than 2147483647.

pastedImage_6.png

I'm using MCUXpresso IDE v10.3.0
SDK_2.x_EVK-MIMXRT1060 v2.5.0

I've done these settings so far but still no luck.

pastedImage_2.png

pastedImage_3.png

2 回复数

1,375 次查看
jorge_a_vazquez
NXP Employee
NXP Employee

Hi Vivien Lin

The debug console is implemented with variables of 32 bits,  so in a low-level driver, it uses a "float to string" converter, this converter work with int32_t variables (0x7FFF_FFFF or 2147483647), this why the actual value is truncated.

You can go to the ConvertFloatRadixNumToString in the fsl_str.c file and change a,b,c, and uc to be int64_t variables (please note that the casting also has to change).

static int32_t ConvertFloatRadixNumToString(char *numstr, void *nump, int32_t radix, uint32_t precision_width)
{
//    int32_t a;
//    int32_t b;
//    int32_t c;
//    int32_t i;
  int64_t a;
     int64_t b;
     int64_t c;
     int64_t i;
    uint32_t uc;


.....

.....

 a = (int64_t)intpart;
    if (a == 0)
    {
        *nstrp++ = '0';
        ++nlen;
    }
    else
    {
        while (a != 0)
        {
            b = (int64_t)a / (int32_t)radix;
            c = (int64_t)a - ((int64_t)b * (int32_t)radix);
            if (c < 0)
            {
                uc = (uint64_t)c;
                c = (int64_t)(~uc) + 1 + '0';
            }
            else
            {
                c = c + '0';
            }
            a = b;
            *nstrp++ = (char)c;
            ++nlen;
        }
    }

pastedImage_1.png

Hope this helps

Regards

Jorge Alcala

1,375 次查看
vivienl
Contributor I

Thanks! It works now.