This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

floating point calculations

hi all, i want to calculate the result of the expression

ah = (range * count*10*resolution)/(3600*1000);

and later add it to the previous value of it
ahfinal = ahfinal + ah;


in brief to explain what i want actually is: count is the count of pulses on timer/counter , now these pulses are caliberated as

range ------> 1000 pulses
xxxx -------> count pulses

now these are to be cailberated into one hour

so ah = xxxx/3600;
now i need a resolution of (1 or 2 or 3 decimals depending on the variable resolution. next the final result should be integrated( i mean added to its previous value ahfinal = ahfinal+ah)


here
range (25, 75,100)
resolution(1, 2, 3)
count(some bog number assume around 1000).

i dont know how to deal with floating point values in microcontroller programming. can anyone help me

thanks in advance
narender

Parents
  • "if i do thhis will it work in microcontroller programming"

    usually not unless you have a really smart compiler

    try

    ah = (((float)count * (float)range)/(3600.0 * 1000.0));

    That should get you the result you want. Though if you using an 8 bit uC, you way want to investigate using fixed point arithmatic instead of floating point. If your doing this calculation many times, you can give your uP significant performance increase.


    Andy

Reply
  • "if i do thhis will it work in microcontroller programming"

    usually not unless you have a really smart compiler

    try

    ah = (((float)count * (float)range)/(3600.0 * 1000.0));

    That should get you the result you want. Though if you using an 8 bit uC, you way want to investigate using fixed point arithmatic instead of floating point. If your doing this calculation many times, you can give your uP significant performance increase.


    Andy

Children