// ============================================================ // // factorial.h // // Copyright 2002, Dennis Meilicke and Rene Peralta // // ============================================================ // // Description: // // NTTL Implementation of: // Product // Factorial // // ============================================================ #ifndef __nttl_factorial__ #define __nttl_factorial__ template< class T > void Product( T *Prod, size_t begin, size_t end ) // // Description: // // Compute product = begin * (begin + 1 ) * ... * end // // Notes: // // Since 1000! is around 2500 decimal digits, begin and end are // limited to being scalars. This could be relaxed... Try // parameterizing the begin and end types... That is, consider: // // template< class R, class T > // R Product( const T &begin, const T &end ) // // This would allow small products of consecutive large numbers // to be easily calculated. Don't know why anyone would need // this, but... // { *Prod = 1; size_t beg; for( beg=begin ; beg<=end ; beg++ ) *Prod *= beg; } // ============================================================ template< class T > void Factorial( T *Prod, size_t end ) { Product( Prod, 2, end ); } #endif