Shifting the input in C to speed up the process

Status
Not open for further replies.

tom_hanks

Full Member level 5
Joined
Aug 28, 2003
Messages
243
Helped
14
Reputation
28
Reaction score
1
Trophy points
1,298
Activity points
1,571
i want to do following calculation in C...

Multiply by .62536
Multiply by 9.46344

can any one suggest >>,<< method to solve this prob.

ex:
for .62536,
=(((x <<2)+3)/6)

any comments are welcome!!
:
 

Re: best division factor

Hello,
I'm not sure want you exactly mean?
Anyways, try shifting the input by 1 bit ,3 bits and 12 bits then add the three shifted versions; you'll get x*0.625244

Then try shifting by 1 bit then by 5 bits then subtract both ,this would give 0.46875 then add to 9*x ,this would lead to 9.46875 .

Just curious, why do you need that?And why not just multiplying directly by 0.62536 and 9.46344 ?
 

Re: best division factor

it is to speed up the process...
can you guide, how can you decided to shift 1,3,12 bit and add that together...

i am fool in this methodology
 

Re: best division factor

Hello,
I first divided your number into two parts :0.625 and 0.00036 .The 0.625 part equals 5/8 which can be considered as 1/2 + 1/8 hence the shift by 1 and 3 bits .
For .0036, the nearest number I could find was 1/2^12 which is .000244 .If you add also 1/2^13 ,you'll get 1/2^12 + 1/2^13 = 0.000366 ,I've just noticed that now .
So, to get the required number ,shift by 1,3,12 and 13 bits then add .
I hope that this combination gives satisfactory results to you .
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…