Re: A89: Re: What the heck is wrong with this?!


[Prev][Next][Index][Thread]

Re: A89: Re: What the heck is wrong with this?!




 > yeah, l found this out a little while ago, it's probably the best way l 
 > think.  And, tigcc seems to sort of simplify the expression for you before it 
 > assembles the program.

Well, it's gcc, which has a fairly agressive optimizer.

 > >     x = ( 3891 * y ) >> 10;
 > 
 > how does the above work?

Right shift by n is equal to a divide by 2^n (under normal
circumstances). Therefore, >> 10 is equal to a divide by 1024.
3.8 * 1024 is 3891.2; since you want to remain in integer space, you
just round it down to 3891. Effectively you multiply with 3.7998047,
which is quite close to 3.8. However, shifting is *much* quicker than 
division.

Best Regards,

Zoltan



References: