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.

IQMath bug?

I have stumbled upon a possible bug in IQMath library!!

here is the description

z = x * y where x & y are both float and can take different values; z is float too.

zQ16 = _FtoIQ16(z);  //zQ16 is of type _iq16

if x = -25.0 (say)  and y = 0.0

I expect  zQ16  to be 0 , instead the call is returnihng a value 0xFFFE0000

I am using c6472 EVM. I am using IQmath v213 , inline_all case

Please help.

 

  • This is not limited to the inline version.

    I am not sure which forum is the right one to get problems with the IQMath library addressed, but we will get this to the right place.

    This can be duplicated with the following code:

    //#define _INLINE_IQMATH
    #include <c6x.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #define GLOBAL_Q 16
    #ifdef _INLINE_IQMATH
    # include "IQmath_inline_all.h"
    #else /* _INLINE_IQMATH */
    # include "IQmath.h"
    #endif /* _INLINE_IQMATH */

    /*
    z = x * y where x & y are both float and can take different values; z is float too.

    zQ16 = _FtoIQ16(z);  //zQ16 is of type _iq16

    if x = -25.0 (say)  and y = 0.0

    I expect  zQ16  to be 0 , instead the call is returning a value 0xFFFE0000
    */

    void main()
    {
        _iq16 zQ16;
        float x, y, z;
       
        x = -25.0;
        y = 0.0;
        z = x * y;
        zQ16 = _FtoIQ16(z);  //zQ16 is of type _iq16
    }

    Regards,
    RandyP

  • Randy,

    Thanks for bringing this issue to our notice. We have been able to replicate the issue using your code and have come to the conclusion that the IQMath function FtoIQ is not designed to handle the -0.0 value generated as a product of x and y. Hence with the current release of the library it appears the developers need to introduce an explicit check in the code to handle this scenario.  As per IEEE 754 standard for single precision floating point numbers

    ;;              31  30        23 22                                 0
    ;;             +-----------------------------------------------------+
    ;;             | s |      e     |                 f                  |
    ;;             +-----------------------------------------------------+

    ;;
    ;;             Value = (-1)^s * 2^(e-127) * 1.f

    ;;

    ;;             where: e = 1 to 254, f = 0.000000000 to ~1.0 (with
    ;;                             exponent bias of 127)
    ;;                    e = 0, f = 0, s = 0, Value = 0.0
    ;;                    e = 0 and f != 0 case cannot occur in IQ math
    ;;                    e = 255 case cannot occur in IQ math

    Hence with this representation -0.0 can be represented using s=1 e=0 f=0 i.e 0x80000000h

    Regards,

    Rahul

  • SNBANIK,

    Thank you for bringing this to our attention.

    Rahul,

    Can you recommend an explicit check for the developers to use in their code?

    Regards,
    RandyP