~igraph/igraph/0.5-main

« back to all changes in this revision

Viewing changes to src/bliss_utils.cc

  • Committer: Gabor Csardi
  • Date: 2012-10-16 20:08:16 UTC
  • Revision ID: csardi.gabor@gmail.com-20121016200816-z42xst2rhl32sauo
More bliss updates to make it compile on Solaris (and hopefully windows).

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
/* FSF address fixed in the above notice on 1 Oct 2009 by Tamas Nepusz */
19
19
 
 
20
#include "bliss_utils.hh"
 
21
#include "bliss_bignum.hh"
 
22
 
 
23
using namespace std;
 
24
 
 
25
#include <cstring>
 
26
 
 
27
#if defined(BLISS_USE_GMP)
 
28
 
 
29
namespace igraph {
 
30
 
 
31
int BigNum::tostring(char **str) { 
 
32
  *str=igraph_Calloc(mpz_sizeinbase(v, 10)+2, char);
 
33
  if (! *str) { 
 
34
    IGRAPH_ERROR("Cannot convert big number to string", IGRAPH_ENOMEM);
 
35
  }
 
36
  mpz_get_str(*str, 10, v);
 
37
  return 0;
 
38
}
 
39
 
 
40
}
 
41
 
 
42
#else
 
43
 
 
44
namespace igraph {
 
45
 
 
46
int BigNum::tostring(char **str) {
 
47
  int size=static_cast<int>( (log(abs(v))/log(10.0))+4 );
 
48
  *str=igraph_Calloc(size, char );
 
49
  if (! *str) {
 
50
    IGRAPH_ERROR("Cannot convert big number to string", IGRAPH_ENOMEM);
 
51
  }
 
52
  std::stringstream ss;
 
53
  ss << v;
 
54
  strncpy(*str, ss.str().c_str(), size);
 
55
  return 0;
 
56
}
 
57
 
 
58
}
 
59
 
 
60
#endif