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.

floating points in the CC3200

Other Parts Discussed in Thread: CC3200


Hi,

       I have a question about the floating point syntax for the CC3200. It seems that the CC3200 give the correct value for a particular syntax but a false value for another syntax which is equivalent.

I read the adc and print it out using the following command,

UART_PRINT("\n\r ADC Voltage = %4.2fV \n\r",adcVoltageValue);

However,

adcVoltageValue = adcReading*(1.4/4096);             always gives     65536.00

adcVoltageValue = adcReading*(14/10)*(1/4096);   always gives     0.00

and

adcVoltageValue = (((adcReading*14)/10)/4096);   gives the correct value.

Can any one please provide any pointers to what I may be missing. My floating point support is fpalib.

Thanks.

  • Hi Umar,

    in adcVoltageValue = adcReading*(14/10)*(1/4096); -> (1/4096) is treated as integer division and that will result in 0. To force floating division operation you need to type cast either as double ie (((double)1)/4096).

    in adcVoltageValue = adcReading*(1.4/4096); type cast either as double as double hold more precise value than float.



    Regards,
    Aashish
  • Hi,
    What is the type of adcVoltageValue and adcReading? can you provide more details about your compiler?
    if adcVoltageValue is float , then:
    adcVoltageValue = adcReading*(1.4/4096); //should work as expected since most compilers treat float*int and float/int as float

    adcVoltageValue = adcReading*(14/10)*(1/4096); //will not work since (1/4096) is zero because both operands are integers ,also 14/10 = 1 for the same reason

    adcVoltageValue = (((adcReading*14)/10)/4096); //will work but not as accurate as it should be when adcReading is integer, because there will be integer approximation when the result of (adcReading*14) is divided by 10 and then when the result is divided by 4096

    the best approach is to use type casting as Aashish pointed.
    adcVoltageValue = (float)adcReading*1.4/4096.0;

    Good luck,
    Jaafar
  • Hi Umar,


    We are closing this thread, for follow up queries please open a new thread and add a link to this one for reference.


    Regards,
    Aashish