CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418451
1
/*
2
* Normaliz
3
* Copyright (C) 2007-2014 Winfried Bruns, Bogdan Ichim, Christof Soeger
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*
17
* As an exception, when this program is distributed through (i) the App Store
18
* by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or (iii) Google Play
19
* by Google Inc., then that store may impose any digital rights management,
20
* device limits and/or redistribution restrictions that are required by its
21
* terms of service.
22
*/
23
24
#ifndef INTEGER_H_
25
#define INTEGER_H_
26
27
#include <libQnormaliz/Qgeneral.h>
28
29
#include <list>
30
#include <vector>
31
#include <string>
32
#include <limits.h>
33
34
//---------------------------------------------------------------------------
35
36
namespace libQnormaliz {
37
using namespace std;
38
39
//---------------------------------------------------------------------------
40
// Basic functions
41
//---------------------------------------------------------------------------
42
43
// returns the absolute value of a
44
template<typename Number> inline Number Iabs(const Number& a) {
45
return (a>=0) ? (a) : Number(-a);
46
}
47
48
//---------------------------------------------------------------------------
49
// Conversions and checks
50
//---------------------------------------------------------------------------
51
52
// convert val to ret
53
// does the conversion and returns false if it fails
54
bool try_convert(long& ret, const long long& val);
55
inline bool try_convert(long long& ret, const long& val) {assert(false); return true;}
56
bool try_convert(long& ret, const mpz_class& val);
57
bool try_convert(long long& ret, const mpz_class& val);
58
inline bool try_convert(mpz_class& ret, const long& val) {assert(false); return true;}
59
bool try_convert(mpz_class& ret, const long long& val);
60
61
// template for same typ "conversion"
62
template<typename Type>
63
inline bool try_convert(Type& ret, const Type& val) {ret = val; return true;}
64
65
66
bool fits_long_range(long long a);
67
68
template<typename Number>
69
inline bool using_GMP() {
70
return false;
71
}
72
73
template<>
74
inline bool using_GMP<mpq_class>() {
75
return true;
76
}
77
//---------------------------------------------------------------------------
78
79
// Should be completely remoced:
80
template<typename Number>
81
inline bool check_range(const Number& m) {
82
return true;
83
}
84
85
//---------------------------------------------------------------------------
86
// Special functions
87
//---------------------------------------------------------------------------
88
89
//return the number of decimals, needed to write the Number a
90
template<typename Number> size_t decimal_length(Number a);
91
92
//returns b!/a!
93
template<typename Number> Number permutations(const size_t& a, const size_t& b);
94
template<typename Number> Number permutations_modulo(const size_t& a, const size_t& b, long m);
95
96
//---------------------------------------------------------------------------
97
// String conversion functions
98
//---------------------------------------------------------------------------
99
100
// forward declaration to silence clang error:
101
// 'operator<<' should be declared prior to the call site or in the global namespace
102
template <typename T> std::ostream& operator<< (std::ostream& out, const vector<T>& vec);
103
104
template<typename Number> string toString(Number a) {
105
ostringstream ostream;
106
ostream << a;
107
return ostream.str();
108
}
109
/* template<> inline string toString(mpz_class a) {
110
return a.get_str();
111
}*/
112
template<> inline string toString(mpq_class a) {
113
return a.get_str();
114
}
115
116
} // end libnormaliz
117
118
//---------------------------------------------------------------------------
119
#endif /* INTEGER_H_ */
120
//---------------------------------------------------------------------------
121
122