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.

TMS320F28034: The precision of positive and negative numbers is different when using IQMath.

Part Number: TMS320F28034

Hi Champs,

I ask this for our customer.

Customers have found that negative numbers have less precision than positive numbers when calculating with IQMath23. I tested it with F28069 on my side and I can reproduce customer's problem.

For example, if you calculate -0.00001*0.99, the calculation result is the same with -0.00001*1.

But if it is 0.00001*0.99, the calculation result will be different.

Could you please help explain why this difference occurs? Thanks!

Best Regards,

Julia

  • Hello Julia,

    My best guess for this is that because the maximum of the _iq23 datatype's range is slightly less than the absolute value of the minimum, there is the slightest change in accuracy (see page 10 of the IQMath quick start guide), although this only would be the case if there was not a consistent resolution for the fixed point numbers. I did test this on my side as well, and the value I got when I tested on my side is still within the resolution for the datatype, so it should not be a significant issue.

    Best regards,

    Omer Amir

  • Hi Omer,

    Thank you for your reply! Customers want to know how to solve this problem? They wanted to improve the precision of negative arithmetic. Customer's current method is to firstly convert the negative number into a positive number, do a positive number operation, and then turn it into a negative number. But customer think this method is too cumbersome, and they also do not accept the method of increasing the Q value of IQ math to improve the precision.

    Customer want to know whether this problem can be solved by means of the compiler or by library functions? Thanks!

    Best Regards,

    Julia

  • Hi Julia,

    As far as I know, this is not an issue that the compiler can fix, since the compiler does not have configurability for the fixed-point datatype. I can check with another expert to see if there maybe is some setting that can be changed. Is there a specific reason they do not want to increase the Q value? There are functions that can convert between the global Q and a specific Q type (IQtoIQN and IQNtoIQ), so if the rest of their system uses a specific global Q value there shouldn't be a problem.

    Best regards,

    Omer amir

  • Hi Omer,

    Is there any update on this case? Thanks!

    Best Regards,

    Julia

  • Hi Julia,

    The original owner of this library left, so I contacted one of the experts who took his place, but he is out-of-office until the 12th, so it may take some time. In the mean time, could you ask the customer if there is a specific reason they do not want to increase the Q value? It would help my understanding.

    Best regards,

    Omer Amir

  • Hi Omer,

    Since customers have a lot of code based on IQmath, if the Q value is increased, the code will be modified a lot. Customer are also concerned that there will be overflow problems after increasing the Q value. Thanks!

    Best Regards,

    Julia

  • Hi Julia,

    I discussed with another expert and this was his explanation for what is happening:

    "The effect that you are seeing is because of truncation. Here is a simple example:

    Binary

    Signed Value

    Truncated Binary Value

    Signed Value

    01.1

    1.5

    01.0

    1.0

    01.0

    1.0

    01.0

    1.0

    00.1

    0.5

    00.0

    0.0

    00.0

    0.0

    00.0

    0.0

    11.1

    -0.5

    11.0

    -1.0

    11.0

    -1.0

    11.0

    -1.0

    10.1

    -1.5

    10.0

    -2.0

    10.0

    -2.0

    10.0

    -2.0

    As you can see, positive fraction numbers are truncated to a smaller number while negative fraction numbers are truncated to a bigger number. If you use the IQ23rmpy() function (which does rounding of the mpy result before storing the final 32-bit value) you will get matching values for the example."

    I hope this helps clarify, but it seems like the IQMath library is designed to act in this way.

    Best regards,

    Omer Amir