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: 418386
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
//---------------------------------------------------------------------------
25
26
#include <algorithm>
27
#include <sstream>
28
#include "libQnormaliz/Qinteger.h"
29
#include "libQnormaliz/Qvector_operations.h"
30
31
//---------------------------------------------------------------------------
32
33
namespace libQnormaliz {
34
using namespace std;
35
36
/*
37
bool try_convert(long& ret, const long long& val) {
38
assert(false); return true;
39
}
40
41
bool try_convert(long& ret, const mpq_class& val) {
42
assert(false); return true;
43
}
44
45
bool try_convert(long long& ret, const mpq_class& val) {
46
assert(false); return true;
47
}
48
49
bool try_convert(mpq_class& ret, const long long& val) {
50
assert(false); return true;
51
}
52
53
bool fits_long_range(long long a) {
54
return sizeof(long long) == sizeof(long) || (a <= LONG_MAX && a >= LONG_MIN);
55
}
56
*/
57
//---------------------------------------------------------------------------
58
59
template <typename Number>
60
size_t decimal_length(Number a){
61
/* size_t l=1;
62
if (a<0) {
63
a=-a;
64
l++;
65
}
66
while((a/=10)!=0)
67
l++;*/
68
69
ostringstream test;
70
test << a;
71
// cout << "L " << a << " D " << test.str().size() << endl;
72
return test.str().size();
73
}
74
75
//---------------------------------------------------------------------------
76
77
template <typename Number>
78
Number permutations(const size_t& a, const size_t& b){
79
unsigned long i;
80
Number P=1;
81
for (i = a+1; i <= b; i++) {
82
P*=i;
83
}
84
return P;
85
}
86
87
//---------------------------------------------------------------------------
88
89
template<typename Number>
90
Number permutations_modulo(const size_t& a, const size_t& b, long m) {
91
unsigned long i;
92
Number P=1;
93
for (i = a+1; i <= b; i++) {
94
P*=i; P%=m;
95
}
96
return P;
97
}
98
99
100
101
102
} //end namespace libQnormaliz
103
104