Okay, here's the Java program I was talking about, since someone might
want it and I'm going to be off-list for a while:

---------------------begin code--------------------
/**
 * Let's try the Factorial in BigInteger
 *
 * @author Joel Rees, Altech Corporation, Esaka, Japan
 *         Copyright September 2002
 *         May be copied, modified, and/or used freely.
 *         No warranty. Use at your own risk.
 *
 * @version 0.1
 */


import java.lang.Class;
import java.math.BigInteger;


public class BigFactorial 
{
        public static void main( String[] args )
        {       if ( ( args.length < 1 ) || ( args[ 0 ].charAt( 0 ) == '-' ) )
                {       System.out.println( "Usage: " 
                                /* Okay, this is ridiculous. */
                                + BigFactorial.class.getName() 
                                + " <integer> {, <integer> }" );
                }
                else
                {       for ( int i = 0; i < args.length; ++i )
                        {       BigInteger input = new BigInteger( args[ i ] );
                                System.out.println( 
                                        "("
                                        + input.toString() 
                                        + ")! == " + factorial( input ).toString() );
                        }
                }
        }


        /* Let's not try to blow the stack with the old 
         * forced example of recursion, at any rate.
        */
        public static BigInteger factorial( BigInteger n )
        {       if ( n.compareTo( BigInteger.ZERO ) < 0 )
                {       return new BigInteger( "0" );
                }
                BigInteger result = new BigInteger( "1" );
                while ( n.compareTo( BigInteger.ONE ) > 0 )
                {       result = result.multiply( n );
                        n = n.subtract( BigInteger.ONE );
                }
                return result;
        }
}

----------------------end code---------------------

Should be easy to re-write in Perl.

-- 
Joel Rees <[EMAIL PROTECTED]>

Reply via email to