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/MSP430G2553: Variable is not being assigned the exact value

Part Number: MSP430G2553

Tool/software: Code Composer Studio

Hello!

In my code, I assigned defined a variable in the following way,

float i;

i = 0.29;

However, when I use the step return and add the variable under watch, it shows that

i = 0.289999992

Why this anomaly. How do i rectify it?

Thank You

  • Hello Aditya,

    it looks ok.
    According to IEEE754:
    - single precision (float) gives you 23 bits of significand, 8 bits of exponent, and 1 sign bit,
    - double precision (double) gives you 52 bits of significand, 11 bits of exponent, and 1 sign bit.

    In case of float the best precision you can get is 23*log10(2) = 6.92 of decimal digits.