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.

Passing long double in square root

Other Parts Discussed in Thread: CONTROLSUITE

Hi all,

I am currently using F28335 in my project.

Due to project requirement, I need to have double precision float accuracy for square root and trigonometric function.

In my application, I have included math.h header file.

A sample of the code is below.

#include "math.h"

long double f1 = 1.23456789L;

long double f2 = 0.0L;

f2 = sqrt(f1);

However, the returned value of f2 is in single precision float.

Is there any way to get double precision accuracy without writing my own mathematical function?

Thanks.

Kelvin

  • Did you try already the sqrtl() version of that function? Should be the right one for long double values...

    Regards,
    Joern.

    P.S. see here: http://linux.die.net/man/3/sqrt

  • Hi Joern,

     

    Yes. I had tried using sqrtl() but there was a compiler error (symbol error for unable to recognise the function sqrtl())

     

    I have explicitly include "math.h" in my application.

     

    Thanks

    Kelvin

  • Sorry for not checking that first - at least for C6000 I found these long double functions like sqrtl() within mathl.h (to avoid misunderstandings: with a small 'L' after 'math').

    So please try it again with sqrtl() and including "mathl.h". I hope that it is available for C2000, too.

    Regards,
    Joern.

  • Hi Joern,

     

    Unfortunately, I cannot find mathl.h for C2000. It is strange that C2000 does not support double precision math functions.

     

    Regards,

    Kelvin

  • That's actually strange and it's annoying that in contrast to lots of single TI documents being helpful it is extremely hard to find such a special piece of information. That starts even with that fact, that the search function does not simply include the wikis and all pdf content.

    However, this thread (assuming that it concerns the F28335 as well)  at least makes clear, that the 64bit doubles are handled, although not hardware based, of course. This thread leads somewhat further, it names rts2800_fpu32.lib, which now leads to IQmath Library for C28x. But emulation of 64-bit floating point operations is in the best case mentioned, at least I didn't found it explained.

    So, actually strange - but I don't see where the problem might lie concerning floating point emulation by standard C libraries... maybe a more current development environment comes with long double support, but I don't see why that should not work for C2000 as well.

    I was very nice if that could be answered by someone of the TI people,

    thanks in advance,
    regards,
    Joern.

     

  • Just found spru514 and there on page 93:

    The run-time-support library has been updated to include the necessary long double arithmetic operations
    and conversion functions. All C27x/C28x floating-point run-time-support routines have had their names
    updated.

    So possibly your problem is solveable by updating your CCS (assuming you're working with code composer studio). Maybe it helps the TI people if you'd post your current version of CCS or, at least, of the CL2000 compiler...

    Regards,
    Joern.

    P.S. Respectively possibly looking for the most current controlSuite helps...

  • Hi Joern,

    I am using Code Composer Studio Version 3.3.82.13

    Integrated Development: 5.98.0.393

    Code Generation Tool: v5.2.9

    As mentioned in spru514, long double arithmetic operations (Multiply, divide, add n subtract) are supported by the software emulation. The trigonometric functions for example in math.h although can accepts long double as argument but the returned result is a double (32 bit float). I tried to modify the function prototype definition in math.h from double to long double for the math function but the returned result is incorrect. I suspect the library only accept double. I will update my Code generation tool to the latest version.

    I will try out the controlSuite and see if it helps. So far, i have rewrite the square root, sin and cos function (Based on Taylor series) but they consume too much CPU cycles and highly inefficient. :-(

    Thanks for the advice, Joern.

    Regards,                                                                                                                                                                                                                                                                                                                    Kelvin Khong

     

  • Kelvin Khong said:
    I will try out the controlSuite and see if it helps.

    Hi Kelvin,

    please let us know if that actually helped, because it's likely that others will drive into the same annoying problem, too.

    Concerning efficiency  - as it looks for me as if your device by it's hardware only supports 32 bit floats - it would be interesting if someone knows about maybe already existing algorithms to double the precision by use of less precise floating point operations?

    Regards,
    Joern.

  • Hi Joern,

    I found a math library using Cordic Algorithm. So far, it is the best alternative solution to using math.h for double precision calculation.

    I heard Taylor series expansion + range reduction + table look up is a viable option too but I have not found any free library based on that yet.

    The link below points to the source code for Cordic Math library.

    http://people.sc.fsu.edu/~jburkardt/cpp_src/cordic/cordic.html

    Regards,

    Kelvin Khong