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.

TMS570LC4357: Issue on Floating Point Values

Part Number: TMS570LC4357

Hi TI,

On passing the Float32 value in the parameter of function then that Float variable in the parameter is not taking the exact same value that the user passed. And this issue is observed only for midway values.

For eg: If I passed "1.2" in the parameter, then its taking "1.20000005" and also this behavior is not consistent. Please look into the below set of values:

1.1 => 1.10000002
1.2 => 1.20000005
1.3 => 1.29999995
1.4 => 1.39999998
1.5 => 1.5
1.6 => 1.60000002
1.7 => 1.70000005
1.8 => 1.79999995
1.9 => 1.89999998

Please provide your inputs on the above issue as soon as possible.

Regards,
Parth

  • Hi Chester,

    Thanks for the reply.

    No, didn't get the exact solution from the Floating Point Guide for the issue that I raised as I am not getting this issue during calculation instead of I am seeing this behavior while passing the values to a variable in the parameter of the function.

    And secondly, as per the guide it is mentioned that to resolve this issue we can round off the value to fewer decimal values (from 8 decimal points to 6 or 5) but this will not work for those where I am getting the lesser decimal value. For eg., 1.4 => 1.39999998, 1.8 => 1.79999995, etc.

    Please provide your inputs on the above solution.

    Regards,

    Parth

  • Hi Parth,

    The IEEE 754 floating-point standard requires that numbers be stored in binary format. The floating binary number of floating point decimal value 1.2 is:

    1.0011_0011_0011_0011_0011_010

    value=1.2, to convert the fractional part (0.2) to binary, multiply fractional part with 2 and take the one bit which appears before the decimal point.

    Follow the same procedure with after the decimal point (.) part until it becomes 1.0.

    0.2 * 2 = 0.4 // take 0 and move 0.4 to next step

    0.4 * 2 =0.8  // take 0 and move 0.8 to next step

    0.8 * 2 =1.6 // take 1 and move 0.6 to next step

    0.6 * 2 =1.2 // take 1 and move 0.2 to next step

    0.2 * 2 =0.4 // take 0 and move 0.4 to next step

    0.4 * 2 =0.8 // take 0 and move 0.8 to next step

    ... ... repeat until 23 bits  (for 32-bit floating point, 1 sign bit, 8 exponent bits, and 23 bit fraction number)

    The floating binary number of the fraction number 0.2 is: 0011-0011-0011-0011-0011-001(1), the 24th bit is rounded up --> 0011-0011-0011-0011-0011-010

    Sign bit (1 bit): b0  (positive)

    Exponent bits(8 bits): b01111111 

    Fraction bits (23 bits): 0011-0011-0011-0011-0011-010

    So 1.2 --> b0-01111111-00110011001100110011010 

    In hex format: 0x3F99999A 

    When the code reads the number back, it converts the floating binary number to floating decimal format:

    The fraction number is converted: 1*1/2^3+1*1/2^4+1*1/2^7+1*1/2^8+1*1/2^11+1*1/2^12+1*1/2^15+1*1/2^16+1*1/2^19+1*1/2^20+1*1/2^22=1.200000048

  • I found this useful tool for converting floating decimal number to floating binary number used by all modern CPUs (IEEE 754 floating point).

    https://www.h-schmidt.net/FloatConverter/IEEE754.html