Click to See Complete Forum and Search --> : Long division algorithm for arbitrary prec. numbers.


almo9004
July 20th, 2007, 06:46 PM
First of all: Hi Codeguru.com!
It' feels nice to be part of a community as dedicated as this one!

So, the situation:
I'm working on a program that (ultimately) calculates digits of Phi (1.618...). I've taken the approach which involves calculating the n-th Fibonacci number ( called F(n) ) and dividing it to the preceding number ( F(n-1) ) to get an approximation of Phi. I'm currently working with vectors of short int's ( vector<short> ) as this the fastest type I've tested as a way of producing the Fibonacci numbers.

The thing is that I'm yet to come up with even a working division algorithm for dividing one vector<short> with another.
I have an idea of how it's going to work, you loop every cell in a, in that loop, you put another loop that adds b to a temporary vector, comparing that to a (the dividend) and keeping track of how many times "b goes in a" so to speak.
But this is just horrible from a programmers point-of-view because it will take exponentially forever to calculate numbers with 1000+ digits!

So this is where I need help! In short: Teach me an efficient way of long division a la very big vectors ^^

Best regards

P.S. and, yes, I know that I'm reinventing the wheel, but this is MY project ok? It's my way of progress as a programmer.