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.

CCS/TMS320F28027F: Rounding floating pointing number

Part Number: TMS320F28027F
Other Parts Discussed in Thread: TMS320F28027, CONTROLSUITE

Tool/software: Code Composer Studio

Hi,

I have created a project using fixed point tms320f28027 , and i am performing some floating point arithmetic on adc data so after multiplication with scaling factor i am getting floating point result with very long like 3.584743647 .

How to round this floating point upto four decimal e.g

3.584743647   to 3.5847

Thanks .

  • Indrajit,

    F28027 is fixed point CPU. From you description, I thought IQ format could meet your requirement.

    You can find the related docs at C:\ti\controlSUITE\libs\math\IQmath\v160\doc

    Jack
  • Thanks for your suggestion .
    But right now i am not using IQmath library , instead of that i am using math library . I know it is not the efficient way to do floating point arithmetic on Fixed point device without IQmath . In my case it is not time-critical system and also i don't think any advantages of using IQmath library for my project.
    Thank you.
  • Indrajit,

    Not possible, sorry. Any digital machine has finite numerical precision, so you can't necessarily represent a number with trailing zeros exactly. For example, if you did this...

    #include <math.h>

    volatile float x = 3.584743647;
    volatile float y, z;

    main()
    {
    y = round(x * 10000);
    z = y / 10000;

    ...you would be rounding y to the nearest integer then dividing back to restore the decimal point. With infinite precision it would work, but on a finite precision machine you may not see a number with only four decimal places. With 32-bit floating point you can represent 3.58469987 or 3.58470011, but not 3.58470000. With more bits you'll get better precision, but the issue will still be there. This is true whether the floating point number is emulated in the RTS or not.

    If truncating the decimal places is important you'll need to use an integral data type such as IQ.

    Regards,

    Richard
  • Thanks for clearing my doubts.
    I will use IQmath.
    Thanks.