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.

Funktion __ffsqrtf from "fpu.h" is not defined for 0

Is there a solution or a fast alternative?

  • Rafeal,

    That is interesting.  I just ran a simple test case.  __ffsqrt(0.0) returns the hex value 0x78F00000, which in floating point format maps to 1.#INF (according to CCS watch window).  The software team will need to take a look at this.  I suspect the problem has to do with the numerical method used to compute the sqrt.

    For now, how about doing this:

     if(x == 0.0)
     {
      y = 0.0;
     }
     else
     {
      y = __ffsqrtf(x);
     }

     

    I suppose the real issue here is how small can x be before the sqrt fails.  If you look at float.h in the compiler folder, it defines the smallest value as

    #define FLT_MIN            1.175494351E-38F   /* SMALLEST POSITIVE VALUE   */

    I tried __ffsqrtf() with this value, and it returns y=2.439455e-19, which is not quite correct (correct answer is 1.08420e-19).  This is no doubt due to numerical error.  At least the answer is a real value and not 1.#INF or something like that.  I also tried with x=1e-30, and it correctly returns y=1e-15.

    I suppose you can pick a minimum value for x, and if x is smaller than that you return y=0.0.  Alternately, if x is smaller than the minimum, use the regular sqrt() function in the compiler RTS library instead, as controlled by your if() statement in your code.

    Regards,

    David

     

     

     

  • Hello,

    I think the problem is the first statment in the funktion:

    dst = __eisqrtf32(x);

    because i think the x is in the demominator then.

    Regards Rafael

     

  • Hi Rafeal,

    The macro can be modified in fpu.h to add checks - of course at the cost of cycles.   As David mentions, the numerical method (Newton-Raphson) involves an estimate of 1/sqrt() which causes some precision issues, but the method is very fast and often used.

    The sqrt function in the compilers RTS library will be the most accurate solution we have, but also the slowest.  I believe it is based off of a series expansion.

    Regards,

    Lori

  • Hi,

     

    I need the fastest solution and I think even the if statement will be faster than der original sqrt.

     

    Regards Rafael