source: branches/profile/ARBDB/admath.cxx

Last change on this file was 8607, checked in by westram, 12 years ago

merge from e4fix [8135] [8136] [8137] [8138] [8139] [8140] [8141] [8142] [8143] [8144] [8222]
(this revives the reverted patches [8129] [8130] [8131] [8132]; see [8133])

  • fixes
    • some free/delete mismatches
    • wrong definition of ORF objects (Level was no bit value)
    • amino consensus (failed for columns only containing 'C')
  • rename
    • AA_sequence_term → orf_term
    • ED4_sequence_terminal_basic → ED4_abstract_sequence_terminal
  • cleaned up hierarchy dumps
  • tweaked is_terminal()/to_terminal()
  • 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.