-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmathutils.h
More file actions
48 lines (42 loc) · 860 Bytes
/
mathutils.h
File metadata and controls
48 lines (42 loc) · 860 Bytes
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
// SPDX-FileCopyrightText: 2014-2024 Technical University of Munich
//
// SPDX-License-Identifier: BSD-3-Clause
//
// SPDX-FileContributor: Sebastian Rettenberger
#ifndef UTILS_MATHUTILS_H_
#define UTILS_MATHUTILS_H_
namespace utils {
/**
* A collection of useful math functions
*/
class MathUtils {
public:
/**
* Finds the smallest value x >= a such that x % k == 0
*
* a and k should be of kind "int".
*/
template <typename T>
static auto roundUp(T a, T k) -> T {
return ((a + k - 1) / k) * k;
}
/**
* Computes the greatest common divisor of a and b
*
* @param a
* @param b
* @return
*/
template <typename T>
static auto gcd(T a, T b) -> T {
T c = a % b;
while (c != 0) {
a = b;
b = c;
c = a % b;
}
return b;
}
};
} // namespace utils
#endif // UTILS_MATHUTILS_H_