source: tags/svn.1.5.4/ARBDB/admath.cxx

Last change on this file was 8319, checked in by westram, 14 years ago
  • ignored PERL2ARB interface as referrer (to detect functions that are only used from perl)
    • moved several functions to static scope or removed them (partly reverted by [13155])
    • for some functions it's ok to be only used from perl (e.g. macro support functions). Added comments there!
  • there is still some dead code in there, e.g.
    • read-security is implemented, but unused (and unwanted)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.6 KB
Line 
1// =============================================================== //
2//                                                                 //
3//   File      : admath.cxx                                        //
4//   Purpose   :                                                   //
5//                                                                 //
6//   Institute of Microbiology (Technical University Munich)       //
7//   http://www.arb-home.de/                                       //
8//                                                                 //
9// =============================================================== //
10
11#include <cmath>
12#include <ctime>
13
14#include "gb_local.h"
15
16double GB_log_fak(int n) {
17    // returns log(n!)
18    static int     max_n = 0;
19    static double *res   = 0;
20
21    if (n<=1) return 0.0;       // log 1 = 0
22
23    if (n >= max_n) {
24        double sum = 0;
25        int i;
26        freenull(res);
27        max_n = n + 100;
28        res = (double *)GB_calloc(sizeof(double), max_n);
29        for (i=1; i<max_n; i++) {
30            sum += log((double)i);
31            res[i] = sum;
32        }
33    }
34    return res[n];
35}
36
37// ----------------------------------
38//      random number generation
39
40static int randomSeeded = 0;
41
42int GB_random(int range) {
43    // produces a random number in range [0 .. range-1]
44    if (!randomSeeded) {
45        srand(time(0));
46        randomSeeded = 1;
47    }
48
49#if defined(DEBUG)
50    if (range>RAND_MAX) {
51        printf("Warning: range to big for random granularity (%i > %i)\n", range, RAND_MAX);
52    }
53#endif // DEBUG
54
55    return (int)(rand()*((double)range) / (RAND_MAX+1.0));
56}
Note: See TracBrowser for help on using the repository browser.