diff options
author | Mateusz Chudyk <mateuszchudyk@gmail.com> | 2020-03-02 13:18:15 +0300 |
---|---|---|
committer | Mateusz Chudyk <mateuszchudyk@gmail.com> | 2020-03-27 17:08:05 +0300 |
commit | dcf3a5ebc62849b823e38400873e2de81c8d2e9c (patch) | |
tree | 416a65b3744b950b0ebbccf168070b55fbc10717 | |
parent | f982b997eb4edc4e8dc63b440bd04c28038f7bd9 (diff) |
Add round_up function
-rw-r--r-- | test/utils_test.cc | 7 | ||||
-rw-r--r-- | utils.h | 7 |
2 files changed, 14 insertions, 0 deletions
diff --git a/test/utils_test.cc b/test/utils_test.cc index 8596104..9c2fb06 100644 --- a/test/utils_test.cc +++ b/test/utils_test.cc @@ -78,5 +78,12 @@ TEST_CASE("Static loop with mult-dim iterator (Iterator<5, 2>)",) { CHECK(result == 11223344); } +TEST_CASE("Round up",) { + CHECK(round_up(0, 5) == 0); + CHECK(round_up(1, 5) == 5); + CHECK(round_up(4, 5) == 5); + CHECK(round_up(6, 5) == 10); +} + } } @@ -199,4 +199,11 @@ __attribute__((always_inline)) static inline void StaticLoop(Args&&... args) { StaticLoop<Body, typename StaticLoopIterator::next>(std::forward<Args>(args)...); } +/* + * Round up + */ +static constexpr Index round_up(Index value, Index factor) { + return (value + factor - 1) / factor * factor; +} + } |