At last night's clinic, we were discussing the problem of calculating
the factorial of large numbers in full precision.  When the building
alarm kicked us out at 9:30, I was waiting for a compile to complete.

Here's a followup (mostly for Neil's benefit, since he seemed to be
somewhat interested).

I downloaded and built this library.

        CLN - Class Library for Numbers
        http://www.ginac.de/CLN/

Then I compiled and linked this program with it.

        #include <cln/integer.h>
        #include <cln/io.h>
        #include <cln/integer_io.h>

        main(int argc, const char *argv[])
        {
            for (int i = 1; i < argc; i++) {
                char *endptr = NULL;
                unsigned long n = strtoul(argv[i], &endptr, 10);
                if (*endptr) {
                    std::cerr << argv[i] << " not numeric" << std::endl;
                } else {
                    cln::cl_I nf = cln::factorial(n);
                    std::cout << n << "! = " << nf << std::endl;
                }
            }
        }

Then I ran it:

        bash$ time ./factorial 1000000 > /tmp/1000000!

        real    1m6.455s
        user    1m5.445s
        sys     0m1.010s
        bash$ wc /tmp/1000000!
              1       3 5565721 /tmp/1000000!
        bash$ echo `head -30c /tmp/1000000\!` ... `tail -30c /tmp/1000000\!`
        1000000! = 8263931688331240062 ... 00000000000000000000000000000

Just over a minute, including the I/O.  Pretty speedy...

I read somewhere that 1,000,000! was first computed in full precision
in 1986 on a VAX.  I don't remember how many days or weeks the
computation ran, and I can't find the book where I read it.

-- 
Bob Miller                              K<bob>
kbobsoft software consulting
http://kbobsoft.com                     [EMAIL PROTECTED]
_______________________________________________
EuG-LUG mailing list
[EMAIL PROTECTED]
http://mailman.efn.org/cgi-bin/listinfo/eug-lug

Reply via email to