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.

Float number multiplication

Other Parts Discussed in Thread: TMS320C28346

Hi,

I am using TMS320C28346

When I write:

 

float f;

long long s64_dbg;

f = 2.6 * 2.0;

s64_dbg = f;

_______________ I get s64_dbg = 5 and that is ok

 

But when I write:

 

float f;

long long s64_dbg;

f = 200000000.6 * 2.0;

s64_dbg = f;

 

_______________ I get s64_dbg = 400000000 while I expecting to get 200000001

 

Anybody has a clue?

 

 

 

  • you meant you expect 400000001?!

     

    float is 32 bit. 

    If I do the same math in MATLAB it gives the same (40000000) answer.

     

    I'm not sure if C2000 supports double precision. If it does, declaring your f to double may give you the correct answer.

     

     

  • Hi Itai Raz,

    As you have used float, its a 32 bit data, which can handle data till 4 294 967 295.

    And your result is well with in limits.

    I am curious to know, how you are expecting 200 000 001. And why not 400 000 001.

    Regards,

    Mohan

  • floating point number are defined by ieee 754. the precision of the number is not evenly distributed. it is more precise around 0, and less precise away from 0. Although the number (200000000.6) is within the range, the single precision can not represent the .6 near 200000000. That's why single(200000000.6) = 200000000. Double precision (64bit) gives the correct answer. 

     

    see http://en.wikipedia.org/wiki/Single_precision_floating-point_format for some details. The range of a single is well beyond 2^32 but to 3.4x10^38.