[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Large factorials?

From: Ted Harding
Subject: Re: Large factorials?
Date: Thu, 28 Aug 1997 11:23:27 +0100 (GMT+0100)

( Re Message From: M. Schmidt )
> I have tried to find a hint in the octave documentation, but couldn't 
> find one regarding the subject and the following:
> Is there an easy way in octave
>    either provided by built-in capabilities,
>    or via programming,
>    or via setup,
>    or via selection of parameters
> to get large factorials not as floating point numbers
> but as representation of very long integers.
> E.g. 50! (or in octave: prod(1:50)) does need more than 60 digits.
> How can this be handled to output not in floating point numbers 
> but as 60+ digit integer??
> I would be happy to get helpful answers as soon as possible
> and I appreciate your feedback.
> Thanks in advance
> Michael
> -- 
> Michael Schmidt                    address@hidden
>                     SAMBA Admin
> Server fuer / Server for  MS + Win95 + WinNT + LANManager
>               Fachhochschule Koblenz

Since 50! > 10^60, the number cannot be represented exactly in 32-bit
floating point. Therefore you are basically stuck.

In /theory/ it is possible to program "symbolic" arithmetic in octave,
i.e. (for istance) 123 * 57 could be worked out by breaking it down
into ["1","2","3","*","5","7"] and feeding this to an octave program which
would manipulate it and return ["7","0","1","1"], but I wouldn't like to
do this unless I really had to. However, this would allow you to do
arbitrary-precision arithmetic within octave.

On my UNIX (actually Linux) system I have the "arbitrary precision
calculator" called "bc" which is something of a UNIX classic. This is
ideal for that type of calculation; here is a short "bc" session for 50!
address@hidden:~# bc -l
bc 1.02 (Mar 3, 92) Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
for(i=1;i<51;i++) j=j*i
Since you can run "bc" as a system task from within octave (provided of
course you're on a UNIX-like system which allows that to be done), if I
needed to get this long string of digits into octave then that's how I
would do it. But you still wouldn't be able to use the string for /exact/
arithmetic calculation within octave by normal methods.

Best wishes,
Ted.                                    (address@hidden)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]