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 | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 5739/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 07-14-05 09:52 PM Link | Quote
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.
Dish

Spiny
Level: 38

Posts: 438/596
EXP: 355646
For next: 14801

Since: 03-15-04
From: Disch

Since last post: 18 days
Last activity: 18 days
Posted on 07-14-05 10:35 PM Link | Quote
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
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 5758/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 07-15-05 06:37 AM Link | Quote
Cool, I knew I could do something useful with that remainder. Now I just have to get it to actually work.
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
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.004 seconds.