Botan
3.7.1
Crypto and TLS for C&
Toggle main menu visibility
Main Page
Related Pages
Topics
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Functions
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
r
s
t
u
v
w
x
z
Variables
Typedefs
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
r
s
t
u
v
w
x
Enumerations
a
c
d
e
f
g
h
k
l
m
n
o
p
r
s
t
u
v
w
Enumerator
c
d
f
i
m
n
r
s
t
Concepts
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Functions
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
Typedefs
a
b
c
d
f
h
i
m
n
o
p
r
s
t
u
v
w
Enumerations
b
c
d
e
k
m
n
o
p
s
t
x
Enumerator
_
a
b
c
d
e
f
h
k
l
m
n
p
q
r
s
t
u
w
x
Related Symbols
b
c
d
e
f
k
o
p
s
t
x
Files
File List
File Members
All
_
a
b
c
d
e
f
i
k
m
n
o
p
q
s
t
u
w
x
y
z
Functions
b
c
Variables
Typedefs
b
c
e
p
t
Enumerations
Enumerator
b
c
d
e
k
n
Macros
_
a
b
c
f
m
n
q
s
t
w
src
lib
utils
rounding.h
Go to the documentation of this file.
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
* Integer rounding
17
*
18
* Returns an integer z such that n <= z <= n + align_to
19
* and z % align_to == 0
20
*
21
* @param n an integer
22
* @param align_to the alignment boundary
23
* @return n rounded up to a multiple of align_to
24
*/
25
constexpr
inline
size_t
round_up
(
size_t
n,
size_t
align_to) {
26
// Arguably returning n in this case would also be sensible
27
BOTAN_ARG_CHECK
(align_to != 0,
"align_to must not be 0"
);
28
29
if
(n % align_to > 0) {
30
const
size_t
adj = align_to - (n % align_to);
31
BOTAN_ARG_CHECK
(n + adj >= n,
"Integer overflow during rounding"
);
32
n += adj;
33
}
34
return
n;
35
}
25
constexpr
inline
size_t
round_up
(
size_t
n,
size_t
align_to) {
…
}
36
37
}
// namespace Botan
38
39
#endif
BOTAN_ARG_CHECK
#define BOTAN_ARG_CHECK(expr, msg)
Definition
assert.h:29
Botan
Definition
alg_id.cpp:13
Botan::round_up
constexpr size_t round_up(size_t n, size_t align_to)
Definition
rounding.h:25
Generated by
1.12.0