http://www.faireal.net/demo/factorial
The basic idea is simple:
var UNIT = Math.pow( 10, 12 ); var myTable = [ 1 ]; var nWork, i; for( var n = 2; n <= nSmallNumber; n++ ) { var nTableSize = myTable.length; var nOverflow = 0; for( i = 0; i < nTableSize; i++ ) { nWork = nOverflow + myTable[ i ] * n; myTable[ i ] = nWork % UNIT; nOverflow = ( nWork - myTable[ i ] ) / UNIT; } if( nOverflow ) myTable[ i ] = nOverflow; }
When the loop is done, you have the result in myTable. Don't forget to do zero-paddings. For instance, if myTable[3] = 1234567890, it means "001234567890".
seelie317 (at) faireal.net[index]