Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 26th, 2002, 02:18 PM
majglow majglow is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Posts: 3 majglow User rank is Private First Class (20 - 50 Reputation Level)majglow User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Divide algorithm

Hello,

I'm working on a big number library (for learning purposes). I'm trying to come up with the best divide function for an arbitraraly long number (multiple of 32 bits - dword).

What would be best?

Repeated subtraction? or a combination of bit shifts and repeated subtraction?

what has the best worst case run time? average run time?

What would be the best way to come up with the combination of bit shifts + subtraction?

-cARL
Comments on this post
Gran Roguismo agrees!
BaronVonDoppleG agrees!

Reply With Quote
  #2  
Old March 2nd, 2002, 12:23 PM
WoR WoR is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Posts: 23 WoR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
repeated subtraction can be exponentiol in hte number of bits used; example:
bigNumber_N_bits / 1
needs 2 exp N subtractions. Each subtraction is again linear in N
So the result will be O(N*expN) (less than perfect)

shifting will be log in each output bit
with potential N output bits you get
O(NlogN) (better and likely optimal in O() notation)

As for the constants (practical programming), doing a full subtraction for each output bit is tough.
You might want to consider working only on a limited window of bits and keeping track of the operations you missed on the data outside of the window.
I don't know if it works at all (just an idea). It certainly won't spare you any of the O() operations,
but might localize data access a bit more and thus run faster. Window size should grow with log of bitnumber N, else the number of operations stored will be linear in N and you don't gain anything.

I hope this helps
Comments on this post
Gran Roguismo agrees!
BaronVonDoppleG agrees!

Reply With Quote
  #3  
Old March 13th, 2002, 08:46 PM
The Ostrich The Ostrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2002
Location: Oxford, UK
Posts: 31 The Ostrich User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
The fastest known division algorithm (for normal cases) is called non-restoring division. If you do a search on google, you'll get plenty of hits (its what CPUs use).
Comments on this post
Gran Roguismo agrees!
BaronVonDoppleG agrees!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Divide algorithm


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway