Skip to main content
gamedev.net
🔒 Locked

Fast Division Algorithm?

Started by uber_n00b Oct 28, 2003 at 5:39 PM 6 replies 1.3k views
Original Post
uber_n00b
uber_n00b
I'm doing a research project for school which compares the binomial theorem to a particular method I thought up and checks the speed of generation of some parts of pascal's triangle. Unfortunately, the best division algorithm I could come up with was something like this: //precondition: numerator can definitely be divided by //denominator evenly newnumber=denominator quotient=1 While(newnumber!=numerator) { newnumber+=denominator quotient++ } This method works, but unfortunately it is very slow for small values for the denominator or large values of the numerator (I need to calculate up to 32! on my 550 mhz), and therefore unfairly stacks in favor my method (which uses division of small numbers). Is there ANY other algorithm I could use?. BTW I created a BIGNUM class, the class elements sort of look like this: class NUMBER { NUMBER *next; //points to a sucessive digit (tens if this is //the ones int datum; //holds one digit of a number }; class BIGNUM { NUMBER *head //keeps track of the memory address of the unit // digit }; As you can see, this further complicates the issue as I can't just do long division because the numerator and the denominator could both be numbers larger than 20 digits easily. Any ideas? I consider myself good at computer science, but this problem is beyond me. I am also open to completely redesigning the class if someone has a really good suggestion. [edited by - uber_n00b on October 28, 2003 6:40:32 PM]
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
Timbatron
Timbatron
I''m pretty sure there is a BigInt in the standard library or in Boost... and i''m sure it has a very efficient division. Maybe look for that?
My Page : http://acidbase.computed.net
uber_n00b
uber_n00b
interesting thought. I will have to look around thanks
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
C-Junkie
C-Junkie
more support for my suggestion of banning AP replies to old posts.

necro...
uber_n00b
uber_n00b
::Wonders how you found this topic:: Wow thanks, that was exactly what I was looking for . Unfortunately, it came about 5 months late as I already presented the project and won a measly 4th place in mathematics at my state''s science fair :-\. Thanks though, I was meaning to reimplement the division algorithm because mine was a huge bottleneck. I wish I had been able to use BigInt or Boost but I probably would have been disqualified for plagiarism or something since that was a key component of the project.
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
Matei
Matei
Sorry that this is late, but basically, big integer classes emulate long division, the same way you'd do it by hand in grade school. If you're told to divide 123431 by 15, for example, you don't add 15 repeatedly till you get 123431; rather, you first start with something like 15000 and add 1000's instead of 1's to your quotient, then when that doesn't work anymore try 1500's and add 100's, etc. This reduces the complexity to O(log N) rather than O(N), which is a very big improvement.

[edited by - Matei on June 5, 2004 3:13:45 PM]
Dredge-Master
Dredge-Master
sometimes you are better off converting to a single precision floating point, dividing by it and then using a fast float to int routine. This can let you take advantage of the multiple pipelines on the newer processors.
Beer - the love catalystgood ol' homepage

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.