/src/igraph/src/isomorphism/bliss/bignum.hh
Line | Count | Source |
1 | | #ifndef BLISS_BIGNUM_HH |
2 | | #define BLISS_BIGNUM_HH |
3 | | |
4 | | /* |
5 | | Copyright (c) 2003-2021 Tommi Junttila |
6 | | Released under the GNU Lesser General Public License version 3. |
7 | | |
8 | | This file is part of bliss. |
9 | | |
10 | | bliss is free software: you can redistribute it and/or modify |
11 | | it under the terms of the GNU Lesser General Public License as published by |
12 | | the Free Software Foundation, version 3 of the License. |
13 | | |
14 | | bliss is distributed in the hope that it will be useful, |
15 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | | GNU Lesser General Public License for more details. |
18 | | |
19 | | You should have received a copy of the GNU Lesser General Public License |
20 | | along with bliss. If not, see <http://www.gnu.org/licenses/>. |
21 | | */ |
22 | | |
23 | | #define BLISS_USE_GMP |
24 | | |
25 | | #if defined(BLISS_USE_GMP) |
26 | | #include "internal/gmp_internal.h" |
27 | | #endif |
28 | | |
29 | | #include <cstdlib> |
30 | | #include "defs.hh" |
31 | | |
32 | | namespace bliss { |
33 | | |
34 | | /** |
35 | | * \brief A simple wrapper class for big integers (or approximation of them). |
36 | | * |
37 | | * If the compile time flag BLISS_USE_GMP is set, |
38 | | * then the GNU Multiple Precision Arithmetic library (GMP) is used to |
39 | | * obtain arbitrary precision, otherwise "long double" is used to |
40 | | * approximate big integers. |
41 | | */ |
42 | | |
43 | | #if defined(BLISS_USE_GMP) |
44 | | |
45 | | class BigNum |
46 | | { |
47 | | mpz_t v; |
48 | | public: |
49 | | /** |
50 | | * \brief Create a new big number and set it to zero. |
51 | | */ |
52 | 4.78k | BigNum() {mpz_init(v); } |
53 | | |
54 | | /** |
55 | | * \brief Destroy the number. |
56 | | */ |
57 | 4.78k | ~BigNum() {mpz_clear(v); } |
58 | | |
59 | | /** |
60 | | * \brief Set the number to \a n. |
61 | | */ |
62 | 14.1k | void assign(const int n) {mpz_set_si(v, n); } |
63 | | |
64 | | /** |
65 | | * \brief Multiply the number with \a n. |
66 | | */ |
67 | 131k | void multiply(const int n) {mpz_mul_si(v, v, n); } |
68 | | |
69 | | /** |
70 | | * Get a copy of the internal GNU GMP integer. |
71 | | * The caller is responsible for calling mpz_init before, |
72 | | * and mpz_clear afterwards on the \a result variable. |
73 | | */ |
74 | 4.78k | void get(mpz_t& result) const {mpz_set(result, v); } |
75 | | }; |
76 | | |
77 | | #else |
78 | | |
79 | | class BigNum |
80 | | { |
81 | | long double v; |
82 | | public: |
83 | | /** |
84 | | * \brief Create a new big number and set it to zero. |
85 | | */ |
86 | | BigNum(): v(0.0) {} |
87 | | |
88 | | /** |
89 | | * \brief Set the number to \a n. |
90 | | */ |
91 | | void assign(const int n) {v = (long double)n; } |
92 | | |
93 | | /** |
94 | | * \brief Multiply the number with \a n. |
95 | | */ |
96 | | void multiply(const int n) {v *= (long double)n; } |
97 | | }; |
98 | | |
99 | | #endif |
100 | | |
101 | | } //namespace bliss |
102 | | |
103 | | #endif // BLISS_BIGNUM_HH |