Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - Tricky division
  
User name:
Password:
Reply:
 

UserPost
HyperLamer
Posts: 5758/8210
Cool, I knew I could do something useful with that remainder. Now I just have to get it to actually work.
Dish
Posts: 438/596
You might be on the right track with that. do your 32768 / x and get the result and remainder. Multiply them both by 4, then divide the remainder by x again, add that result to your previous result and the new remainder is your remainder. This means two divisions, which would be pretty slow -- you might be able to speed this up by having a chopped down version of your division routine (the result of the second division can't be greater than 3).

Example:

131072 / 1998 = 65 remainder 1202
32768 / 1998 = 16 remainder 800

16*4 = 64
800*4 = 3200

3200 / 1998 = 1 remainder 1202

64 + 1 = 65, with a remainder of 1202

HyperLamer
Posts: 5739/8210
Alright, well I've been writing some ASM code for Gameboy, but I've run into a snag. I need to do the equation x = 131072 / x. Now, I have division code but it's only 16-bit (can only go up to 65535 / x) and honestly I really don't know how it works; I downloaded it somewhere and it's completely lacking comments. It returns the result and remainder, both 16-bit. I tried doing x = 4 * (32768 / x) - this almost works, but because the decimals get dropped, the result is not quite accurate. Eg: 131072 / 1998 = ~65.6, 32768 / 1998 = ~16.4, and 16.4 * 4 = 65.6. Problem being, since Gameboy has no floating point support, it ends up being 16 * 4 = 64.

Sorry if this is confusing, I'm sleepy. I need to work out a way to do this, preferrably without having to modify the division code.
Acmlm's Board - I2 Archive - Programming - Tricky division


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.010 seconds.