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 multiplication with 1.0 doubles the result

Hi!

 

I've a strange coding issue with multiplication of floats in IAR. Here is the code snippet:

 

 unsigned int TEST (FS *fs){



 float x0, x1, x2;


x0 = 1.0 * fs->x;
x1 = -2.0 * fs->x_1;
x2 = 1.0 * fs->x_2;


return 0;
}

The fs structure contains unsigned ints containing 10 bit ADC values. For any value of member x, the  x0 = 1.0 * fs->x; row yields 2*x  value in the debugger. For example  x=377, then x0=756.0. 

 

The debugger correctly translates x0 as a float. What is the problem here?

  

**Attention** This is a public forum