AnsweredAssumed Answered

Compiller corrupts Floating-point types.

Question asked by Vasya Pupking on Jan 12, 2016
Latest reply on Jan 13, 2016 by Vasya Pupking

I use CodeWarrior IDE version 5.9.0 and MC9S08AW60. I found that it incorrectly handles floating point variables. For the values up to 65535.9999 everything is ok. Values from 65536.0000 becomes 0.0004 greather.  I see 65536.0004 instead 65536.0000. Values starting from 524288.0000 becomes 0.0049 greater. Values starting from 8388608.0000 add 0.0499 and so on. Note, that 65536 = 2^16, 524288 = 2^19, 8388608=2^23. Is there any solution for this problem?

void test_double(void)

{

double val1;

double val2;

U8 i;

char buf[20];

    clr_str(0);

    i=0;

    val1 = 65535.9999;

    sprintf (buf,"%5.4f", val1);

    while (buf[i])

         out_lcd (buf[i++]);

   

    clr_str(1);  

    i=0;

    val2 = 65536.0000;

    sprintf (buf,"%5.4f", val2);

    while (buf[i])

         out_lcd (buf[i++]);

    for(;;);

}

IMG_20160112_085847.jpg

Outcomes