This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28377S: float data add operation output is truncated

Part Number: TMS320F28377S

I used TMS320F28379DEVM to do below test

define global variables

float B = 524288.0;

float C = 0.02;

then execute below statement as below in while infinite loop , but find that B is always 524288.0

 B = B+C;

 

I suspects it should be the rounding mode caused this issue, pls help explain this and give your suggestion to avoid the data truncated to get

un-expected output.

Thanks.

 

 

  • Hi,

    No, it's not rounding, it's standard limitation of floating point math. Since mantissa of single precision float is 24 bits wide, you can add something which is up to 2^24 times smaller. 2^24..2^25 smaller addend is marginal, rounding may or may not help making a change to your sum, and everything smaller than /2^25 will behave as 0.0. Depending on app requirements you should switch to double precision, integers or Q integer fractions.

    Regards,
    Edward
  • Understand the data larger 1/2^25 can take effect for add operation, but 0.02 is larger than 1/2^25, how that issue happen ?
  • I meant that addend smaller 2^24 times compared to bigger addend is marginal. In your case it's
    524288 / 2^24 = 0.03125
    Such relatively small addend may or may not lead to change between bigger addend and the sum, it depends on rounding. On FP machine with rounding to nearest even
    524288 + 0.03125= 524288
    524288 + 0.0312500037252903 = 524288.0625
    524288.0625 + 0.0312500037252903 = 524288.125
    .. but no matter, as a rule of thumb you should expect that adding relatively very small float to relatively much bigger float you may lose your smaller addend completely. “Truncation” margin is ~1/ 2^ 24 for float and ~1/ 2^53 for double.

    Regards,
    Edward

  • understand, great thanks.