/**************************************************************************** Kalkulon - A programmable calculator for programmers This is an example Kalkulon script. To load from within Kalkulon: Load("examples/scriptname.k") then you can call functions like: funcname() or funcname(arg0, ...) Author: Juergen Holetzeck 2003 - 2007 e-mail: contact@kalkulon.de homepage: www.kalkulon.de ****************************************************************************/ /////////////////////////////////////////////////////////////////////////// // implementation copied from Numerical Recipes http://www.nr.com/ // // gamma function // factorial // binomial coeffcient //returns the value ln[gamma(xx)] for xx > 0 gammln(xx) = ( cof={76.18009172947146,-86.50532032941677,24.01409824083091,-1.231739572450155,0.1208650973866179e-2,-0.5395239384953e-5}, y=x=xx, tmp=x+5.5, tmp -= (x+0.5)*ln(tmp), ser=1.000000000190015, for (j=0;j<=5;j++;ser += cof[j]/++y), // return -tmp+ln(2.5066282746310005*ser/x) ); //returns the value n! (as a floating-point number) factrl(n) = ( if (n < 0; Error("Negative factorial")), if (n > 32; exp(gammln(n+1)); // else res=1, while (n; res*=n--), res ) ); //returns ln(n!). factln(n) = gammln(n+1); //returns the binomial coeffcient (n over k) bico(n, k) = floor(0.5+exp(factln(n)-factln(k)-factln(n-k)));