Coverage Report

Created: 2023-09-25 06:33

/src/botan/build/include/botan/internal/rounding.h
Line
Count
Source
1
/*
2
* Integer Rounding Functions
3
* (C) 1999-2007 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_ROUNDING_H_
9
#define BOTAN_ROUNDING_H_
10
11
#include <botan/types.h>
12
13
namespace Botan {
14
15
/**
16
* Round up
17
* @param n a non-negative integer
18
* @param align_to the alignment boundary
19
* @return n rounded up to a multiple of align_to
20
*/
21
44.2k
inline size_t round_up(size_t n, size_t align_to) {
22
44.2k
   BOTAN_ARG_CHECK(align_to != 0, "align_to must not be 0");
23
24
44.2k
   if(n % align_to) {
25
37.9k
      n += align_to - (n % align_to);
26
37.9k
   }
27
44.2k
   return n;
28
44.2k
}
29
30
/**
31
* Round down
32
* @param n an integer
33
* @param align_to the alignment boundary
34
* @return n rounded down to a multiple of align_to
35
*/
36
template <typename T>
37
inline constexpr T round_down(T n, T align_to) {
38
   return (align_to == 0) ? n : (n - (n % align_to));
39
}
40
41
}  // namespace Botan
42
43
#endif