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.

PROCESSOR-SDK-J784S4: cfloat operator*(float, cfloat)

Part Number: PROCESSOR-SDK-J784S4

Tool/software:

It seems there is no C++ operator to multiply a float and a cfloat.

I expected it as it exists in usual math and in std C++, cf std::complex operators

It seems either impossible to define one because cfloat is not really a class (outside HostEmu).

inline cfloat operator* (const float& lhs, const cfloat& rhs)
{
    return cfloat(lhs * rhs.r(),  lhs * rhs.i());
}

error #952: nonmember operator requires a parameter with class or enum type

This overloading works with HostEmu. It fails with CGT 4.1.0.

  • Please understand that, while the C++ standards do not define cfloat as a primitive built-in type, the C7x compiler does.  An operator function cannot be defined for a primitive type.  For more details, please see this FAQ (not from TI).  

    This overloading works with HostEmu. It fails with CGT 4.1.0.

    In HE (host emulation), cfloat is modeled as a C++ class, which means you can define an operator function.  This is a limitation of using HE.

    Thanks and regards,

    -George

  • Yes, that was also my understanding, as (poorly) said in my ticket : cfloat is a CGT extension of C/C++ langage.

    My request is that this extension shall be (more) complete, i.e. provides the same operations as the STL does with std::complex<>.


    Most notably the external math product between real and complex values.

  • My request is that this extension shall be (more) complete, i.e. provides the same operations as the STL does with std::complex<>.

    Because std::complex is not a built-in type, it is possible to define the meaning of the multiply operator * for it.  Because cfloat is a built-in type, the meaning of the multiply operator * is pre-defined, and there is no method for changing it.  I suppose we could define an intrinsic for multiplying a cfloat and a float.  But there is no meaningful difference between that and you writing a function that does the same thing.

    Thanks and regards,

    -George

  • I understand the built-in type limitations, and this is my request.

    As TI extended the C langage providing cfloat as a std::complex<float> imitation, it would be fair for the imitation to be complete.
    The same C++ rules forbids to overload operator* as cfloat is built-in. So I shall write a "static inline" function (and EXT_EP-11846 may apply).

    - it's less readable

    - it's potentialy weaker for the optimizer

    - what about vector/SIMD case ?

    Think of :

    cfloat z1, z2, z3;
    float f1, f2, f3
    
    // usual and std portable
    z1 = f2 * z2 + f3 * z3;
    
    // not in the CppCoreGuidelines spirit, not overloadable => distinct name, etc
    z1 = mystd::multfz(f2, z2) + mystd::multfz(f3, z3);
    
  • Thank you for the suggestion.  I filed the entry EXT_EP-11960 to request this change to the compiler.  You are welcome to follow it with that link.  Please understand that filing a request does not guarantee it gets implemented.

    Thanks and regards,

    -George