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.

Using modf( float, float* ) in cmath results in infinite loop

I'm compiling code for the F28335 using CCS5 and the 6.0.3 compiler.  When I #include <cmath> and call modf( float, float* ) I get an infinite loop.  Checking the assembly, it appears the modf( float, float* ) function calls itself in an infinite loop.  I've worked around this issue for now by using the double version of the function, but this needs to be fixed.  Here's the generated assembly of the loop:

;***************************************************************
;* FNAME: _modf__3stdFfPf FR SIZE: 0 *
;* *
;* FUNCTION ENVIRONMENT *
;* *
;* FUNCTION PROPERTIES *
;* 0 Parameter, 0 Auto, 0 SOE *
;***************************************************************

_modf__3stdFfPf:
;*** ----------------------- #pragma LOOP_FLAGS(4096u)
$C$L10:
;*** -----------------------g2:
;*** 198 ----------------------- return modf(x, y);
;*** ; tail recursive call occurs here
;*** 198 ----------------------- goto g2;
BF $C$L10,UNC ; [CPU_] |198|
; branch occurs ; [] |198|
  • C2000 compiler version 6.0.3 hasn't been released yet; are you sure that's the exact version number?  Are there any letters or digits after 6.0.3?

    modf is the double version; modff is the float version.

  • Sorry, I meant 6.0.2.   In the C style math.h, modf is the double version and modff is the float version.  In the C++ style cmath, modf is overloaded to use float or double.

    If I go to the declaration of mof( float, float* ), it takes me to the following lines of code in cpp_inline_math.h:

    inline float modf(float x, float *y)
    { // unpack fraction
    return (float)(modff((float)x, (float *)y));
    }
    
    
    If I then go to the declaration of modff, it takes me to this line of code, also in cpp_inline_math.h:
    #define modff   modf
    
    
    So the floating point version of modf is calling moff with floats which is defined as modf.  That's an infinite loop.
  • Okay thanks.  This is now SDSCM00043847