Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!news.kei.com!newsfeed.internetmci.com!in1.uu.net!munnari.OZ.AU!cs.mu.OZ.AU!munta.cs.mu.OZ.AU!fjh
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Subject: Re: N Factorial
Message-ID: <9533401.3146@mulga.cs.mu.OZ.AU>
Sender: news@cs.mu.OZ.AU (CS-Usenet)
Organization: Computer Science, University of Melbourne, Australia
References: <x6kg.96.30B61C60@unb.ca> <49ec64$5kl@goanna.cs.rmit.EDU.AU>
Date: Wed, 29 Nov 1995 14:52:25 GMT
Lines: 30

ok@goanna.cs.rmit.EDU.AU (Richard A. O'Keefe) writes:

>In fact, I wonder if they were bright enough to write
>	#include <math.h>
>	long factorial(int n) {
>	    return (long)exp(lgamma((double)n + 1));
>	}
>for their C++ version?

The template version is quite fun.

	template <unsigned N>
	struct factorial {
		static unsigned val() { return N*factorial<N-1>::val(); }
	};
	struct factorial<0> {
		static unsigned val() { return 1; }
	};

Try

	int main() { return factorial<1000>::val(); }

and see if your C++ compiler falls over ;-)

--
Fergus Henderson             	WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au              	PGP: finger fjh@128.250.37.3
I will have little or no net access from Nov 30 until Dec 25,
so please email me a copy of any follow-ups.
