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.

TMS320F280048: TMS320F280048

Part Number: TMS320F280048

Hello,

Is library function available for modulo 2 of two float? If yes, what is that?

Thank you,

Victor

 

  • Victor,

    Can you clarify the requirement a little please?

    - for which operation result do you want the modulo-2: division, multiplication, ...?

    - what is your expectation on rounding: round-to-zero, round-to-nearest, ...?

    Regards,

    Richard

  • Hi Richard,

    The modulo 2 division, for example,   24. 6   MOD2DIV   7.1 = 3.3 with  round-to-nearest. Of course I can do it by subtraction in simple WHILE loop

    However I am curious if more smart algorithm and LIB function is available from TI.

    Thank you,

    Victor

  • Victor,

    I believe what you are describing really is 24.6 Modulo 7.1, in other words, there is no Modulo 2 operation involved. This would then just fall into the category of Floating point division for which we have support in the 28004x TMU instruction set. So with the TMU enabled in your project, the standard division operation should lead to the generation/usage of the appropriate TMU floating-point division instruction (which takes 5 pipeline cycles to execute).

    Richard, Victor,

    Let me know if my understanding is not correct.

    Thanks,

    Sira

  • Sira,

    You are right, sorry. What is C-function name for this operation? Is there any user manual for such functions?

    Thank you,

    Victor

  • Victor,

    I think just using "/" will work. % won't since it works only on integer operands. fmod() will work on float operands, but I don't know that the TI compiler will replace this call with a TMU instruction.

    Thanks,

    Sira

  • Hi Victor,

    I would like to clarify my above point a little better:

    You can use the C library function fmod to perform the modulo operation, but this is very slow. It appears to take over 200 cycles.

    A much faster option, if you are trying to compute fmod(a,b) is:

    c = (a/b) - (((int)(a/b))*b);

    Thus, there are two divisions (which the compiler will implement using DIVF32 if the TMU is enabled, which is very fast), and one multiplication.

    Thanks,

    Sira

  • Sorry, Typo above. Correct equation is:

    fmod(a,b) = a - ((int)(a/b)*b);

    Thanks,

    Sira