diff --git a/src/cwt.c b/src/cwt.c index 3e5b559..ac33fd8 100755 --- a/src/cwt.c +++ b/src/cwt.c @@ -9,11 +9,7 @@ C. Torrence and G. Compo, and is available at URL: http://atoc.colorado.edu/rese #include "cwt.h" double factorial(int N) { - if (N > 40) { - printf("This program is only valid for N <= 40 \n"); - return -1.0; - } - double fact[41] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000, + static const double fact[41] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000, 20922789888000, 355687428096000, 6402373705728000, 121645100408832000, 2432902008176640000, 51090942171709440000.0, 1124000727777607680000.0, 25852016738884976640000.0, 620448401733239439360000.0, 15511210043330985984000000.0, 403291461126605635584000000.0, 10888869450418352160768000000.0, 304888344611713860501504000000.0, 8841761993739701954543616000000.0, 265252859812191058636308480000000.0, 8222838654177922817725562880000000.0, @@ -21,6 +17,11 @@ double factorial(int N) { 371993326789901217467999448150835200000000.0, 13763753091226345046315979581580902400000000.0, 523022617466601111760007224100074291200000000.0, 20397882081197443358640281739902897356800000000.0, 815915283247897734345611269596115894272000000000.0 }; + if (N > 40 || N < 0) { + printf("This program is only valid for 0 <= N <= 40 \n"); + return -1.0; + } + return fact[N]; }