Beispiel #1
0
//==================================================================================================
// Double factorial n!!
//==================================================================================================
double log10doublefactorial(int n)
{
	if(n<=1) return log10(1.0);

	// here the useful relation is (2m-1)!!=(2m)! / m! / 2^m
	int m;
	//
	if ( n % 2 == 0 ) m=n/2;
	else m=(n+1)/2;
		
	return log10factorial(2*m) - log10factorial(m) - m*log10(2.0);
}
Beispiel #2
0
main(int argc, char *argv[])
{
      double f, lf;
      char *dummy;

      while (--argc)
      {
            f  = strtod((const char *)(*(++argv)), &dummy);
            if (0.0 == f)
            {
                  puts("0! = 0");
                  continue;
            }
            if (-1.0 == (lf = log10factorial(f)))
            {
                  printf(">>> ERROR: %g! is not a valid expression\n", f);
                  continue;
            }
            if (171.0 > f)
                  printf("%.14g! = %.14g\n", f, pow(10.0, lf));
            else
            {
                  printf("%.14g! = %.14ge+%ld\n", f,
                        pow(10.0, dfrac(lf)), (long)dround(lf));
            }
      }
      lf = log10C(1000000L,750000L);
      printf("\nJust to dazzle with you with big numbers:\n"
            "C(1000000,750000) = %.14ge+%ld\n",
            pow(10.0, dfrac(lf)), (long)dround(lf));
      lf = log10P(1000000L,750000L);
      printf("\n...once more:\n"
            "P(1000000,750000) = %.14ge+%ld\n",
            pow(10.0, dfrac(lf)), (long)dround(lf));
      return EXIT_SUCCESS;
}