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.

Re: Floating point arimatic calculation problem

Other Parts Discussed in Thread: CODECOMPOSER

Hi All,

I am working on Kalman filter implementaion in Msp430. In the process of algorithm I have come across many floating point operations. I have performed calculation of  kalman filter values through python for the same data that I was calculating through MSP430. There was a different which i cant affort. so I have decided to debug step by step and see where exactly the problem is? then this is what i have observed.

I have come acrross this calculation :

current_prob_state = (1-0.9999) * 1.000001

which should result in                                                0.0001000001

but the result that I am seeing in the msp430 is  0.0001000167

I dont really know what happened here. Some one please help he to resolve this issue.


Thanks in advance,
Sri.

  • This is compiler-related. Perhaps you shall check your compiler options and find "float precision settings" or something like that. In IAR it is in "General Options", Floating-point, size of "double": change from 32bit to 64 bit.

  • Hi Illmars,

    As you have suggested I have chaged the floating precession settings to 64. But now, all my float declarations are being shown as error. the error mesage is:

    Multiple markers at this line
        - #1558-D 32-bit floating point operations are not allowed
        - <a href="file:/C:/ti/ccsv5/tools/compiler/dmed/HTML/MSP430/1531.html">#1531-D</a> (ULP 5.2)
         Detected floating point operation(s). Recommend moving them to RAM during run time or not using as these
         are processing/power intensive

    I think I need to redeclare all float variablles. Could you please advice as of how o declare a 64 bit floating variable please.

  • Hi guys thank you all,

    I have solved the issue by
    1. going through illmars suggestion. I have changed the precesion of floating variables.
    Right click on projecct--> properties-->Build-->Advanced options-->language options--> Floating point precision accepted by compiler (--float_operations_allowes)  selected 64 from drop down menu.

    2. Changing the output format formay from Legacy COFF to eabi in
    Right click on projecct--> properties-->general-->Advanced Settings--> Output format

    Thank you so much.
    Sri.

  • The compiler option just did disable support for 32 bit float. Hence theerror when you still use 32 bit float variables.

    For higher precision, use 'double' typeinstead of 'float' type: float = 32bit, double = 64bit.

  • Hi, this is what my CCS is showing, nothing to find about floating point settings?!

    I am also using some floating point to calculate calibrated values inside a menu, so the user can set different values, there the problem also was what you described, but back then I thought this is simply due to the fact that floating point numbers you set sometimes cannot be exactly the value you set them to in the Microprocessor.

    Now what you describes sounds quite nice for me too,but as you see I couldnt find it. And another question for double usage if anyone knows,

    what I can to is coding a if-statement

    if ( float1 >= float 2 )

    can I do exactly the same with a double? does ittake like way more time to compare or use doubles in my code? I dont have quite the feeling for that usage yet, first I was also afraid that a 32 bit comparation wouldnt work in the µC, since the architecture is made for 16 bit, but apperently it does work.

    Thanks a lot.

    Seb

  • seb said:

    what I can to is coding a if-statement

    if ( float1 >= float 2 )

    can I do exactly the same with a double?

    Yes.

    seb said:
    does ittake like way more time to compare or use doubles in my code?

    Not way more, just twice

    seb said:
    first I was also afraid that a 32 bit comparation wouldnt work in the µC

    No worries. Note that desktop calculators uses 8bit CPU's (some uses just 4bit CPU) but they are able to crunch much bigger numbers. How's that? :)

  • Ilmars said:
    Not way more, just twice

    Not necessarily. AFAIK, the size of the exponent is the same for both. So a quick > or < comparison can be done by just comparing the exponent, taking the same time. Only if the exponent is the same, the value needs to be compared.
    But of course it depends on implementation.

  • Ok thanks for Your remarks, now still my question remains:

    1. going through illmars suggestion. I have changed the precesion of floating variables.
    Right click on projecct--> properties-->Build-->Advanced options-->language options--> Floating point precision accepted by compiler (--float_operations_allowes)  selected 64 from drop down menu.

    I could not find that point in my properties as stated above in the screenshot I posted, or perhaps I am just blind , could very probably also be.

    I am using: CCS v 5.1.1.00028

    so any suggestions will help.

    Thank You.

  • Seb, Ilmars' suggestion was about IAR and apparently, sri-sri is also using IAR. Maybe this option doesn't exist in CCS.

    According to the 4.2 compiler guide, in COFF mode, float, double and long double all use 32bit data. There is no 64bit floating point support in CCS for COFF mode. However, in EABI mode, double and long double use 64bit IEEE implementation. So precision (and size) of a float variable solely depends on the used data type.

  • Hey ,

    In which compiler mode you are in? as said by Jens Michael. R u in COFF or EABI?

  • COFF, I am using in all my projects until now, but honestly I did never care about this, because it did work jsut right from day 1 when I startet using the CodeComposer like 4 years ago.

    And as I do not have assambler background, the only thing I care about is if my code will work on my PCB, and I only start questioning my toolchain and coding once errors occur :)

    So if anyone is familiar with practical bits about the different formats I will listen carefully.

**Attention** This is a public forum