Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
11/07/08 10:22
Read: times


 
#159885 - 32-bit fixed point
Responding to: ???'s previous message
You don't specify how often you need to do this.

But the trivial solution is to just use 32-bit variables and let the compiler do the fighting.

2.474 when multiplied by 1000 is an integer 2474.

So you get:
R = 2474 * V / D / 2000
2474 * V has a maximum size of 148440000 which requires 28 bits.

If you want only one division, and merge D and 2000, then that value has a max size of 2000000000 which requires 31 bits.

But the question is how much decimals you want/need if you do this in fixed-point. With a large D, the answer will be less than 1, i.e. will result in the answer zero unless any scaling is performed.

If you skip the three zeroes in the constant 2000, you will get this formula:
R = 2474 * V / D / 2
that will produce a fixed-point answer with three decimals.

V = 60000
C = 1000000
will give the result
in floating point: 0.07422
in fixed point: 74 which (with the three digits of scaling) corresponds to 0.074.

Since 2474 * V is never larger than 148440000, you can rewrite the formula to:
R = 12370 * V / D
which will give you
742 corresponding to (with a 10000 scaling) 0.0742.

Note that integer arithmetic will truncate the answer. You may help out by adding 0.5 before the division to get proper rounding of the answer.

You might be able to squeeze in more fixed-point decimals in the result if you have more knowledge about the true values of V and D, i.e. if they are independent or if D is further limited depending on what range V is in. And if D is large, you can decide to divide D by an extra 10 to get one extra decimal in the answer.

List of 6 messages in thread
TopicAuthorDate
Help need!            01/01/70 00:00      
   be more specific            01/01/70 00:00      
      That is correct!            01/01/70 00:00      
   32-bit fixed point            01/01/70 00:00      
   You could solve it using long            01/01/70 00:00      
      Re: You could solve it using long            01/01/70 00:00      

Back to Subject List