-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.hpp
More file actions
90 lines (76 loc) · 2.29 KB
/
utils.hpp
File metadata and controls
90 lines (76 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* mini-cp is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3
* as published by the Free Software Foundation.
*
* mini-cp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with mini-cp. If not, see http://www.gnu.org/licenses/lgpl-3.0.en.html
*
* Copyright (c) 2018. by Laurent Michel, Pierre Schaus, Pascal Van Hentenryck
*
* Contributions by Heytem Zitoun, Waldemar Cruz, Rebecca Gentzel, Willem Jan Van Hoeve
*/
#pragma once
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
//#define TRACE(...) __VA_ARGS__
#define TRACE(...)
#define TO_STRING(e) #e
inline double division(int numerator, int denominator)
{
return static_cast<double>(numerator) / static_cast<double>(denominator);
}
inline int floorDivision (int numerator, int denominator)
{
return static_cast<int>(std::floor(division(numerator, denominator)));
}
inline int ceilDivision (int numerator, int denominator)
{
return static_cast<int>(std::ceil(division(numerator, denominator)));
}
inline double power(int base, double exponent)
{
return std::pow(static_cast<double>(base), exponent);
}
inline int floorPower (int base, double exponent)
{
return static_cast<int>(std::floor(power(base, exponent)));
}
inline int ceilPower (int base, double exponent)
{
return static_cast<int>(std::ceil(power(base, exponent)));
}
inline double logarithm(int base, int number)
{
return log2(static_cast<double>(number)) / log2(static_cast<double>(base));
}
inline int floorLogarithm (int base, int number)
{
return static_cast<int>(std::floor(logarithm(base, number)));
}
inline int ceilLogarithm(int base, int number)
{
return static_cast<int>((std::ceil(logarithm(base, number))));
}
inline void printError(std::string const & error)
{
std::cerr << "% [ERROR] " << error << std::endl;
}
template<typename T>
void printVector(std::ostream& os, std::vector<T>& vector)
{
if (not vector.empty())
{
os << vector[0];
for (size_t i = 1; i < vector.size(); i += 1)
{
os << "," << vector[i];
};
}
}