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/LAUNCHXL-F28069M: Float Precision

Part Number: LAUNCHXL-F28069M

Tool/software: Code Composer Studio

Dear Everyone,

I have a precision problem about float values. 

#include "math.h"

 is included. I defined 5 different types of float parameters to check how the process works.

float32 p1 = 1.1;
float p2 = 1.1;
float64 p3 = 1.2;
double p4 = 1.3;
long double p5 = 1.4;

The results of these float parameters are below :

When I give these "1.1" values from "Expressions" window, surely the result is the same.

Which means truncation will not work. I know that it is about how CCS: the 64-bit value in memory or many IEEE-754 data converters around translate the value.

What do you do in this kind of situations?

It won't make a huge difference for the calculations but while sending or receiving the values to/from a computer or hmi interface, it looks a bit weird. (I entered 1.1 but it shows me 1.10000002 etc.)

Thank you.

  • Please see compiler documentation. Type sizes are different than one would expect. Both float and double are single precision IEEE754. Long double is just double precision. C floating point literals have 2 precision modifiers. 'F' at the end (like 1.3F) means float, no letter at the end means double and 'L' at the end means long double. So for your long double initializer you should add L at the end, 1.4L. You need to check SPRU514P or similar document, and then 6.4 Data Types.

    Except for zeroed tail of your p5 variable due to missing 'L' in initializer, I see nothing wrong in your pictures.

    Regards
    Edward