in reply to Re: Factorial algorithm execution time
in thread Factorial algorithm execution time
I thought about this method, but I opted to try out a different method. You are correct in saying that much time is spent multiplying numbers. So what we can do is get rid of that multiplication and turn it into addition. This can be easily done by first taking logs of all integers in the factorial calculation, summing those values and finally raising e to that power. For example, 5!=e^(ln(2)*ln(2)*ln(4)*ln(5)). There is only one problem with that. Since Math::BigFloat does not contain a log or exp function, the limited precision of the built in functions creates a rounded answer (try doing 200!)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Factorial algorithm execution time
by Anonymous Monk on Oct 18, 2002 at 23:29 UTC | |
by Aristotle (Chancellor) on Oct 19, 2002 at 01:32 UTC | |
by Anonymous Monk on Oct 19, 2002 at 03:06 UTC | |
by Aristotle (Chancellor) on Oct 19, 2002 at 11:24 UTC | |
by Anonymous Monk on Oct 19, 2002 at 15:38 UTC | |
|
Re^3: Factorial algorithm execution time
by Aristotle (Chancellor) on Oct 18, 2002 at 14:44 UTC | |
|
Re: Re: Re: Factorial algorithm execution time
by gri6507 (Deacon) on Oct 18, 2002 at 16:42 UTC |