Botan 1.10.17
rounding.h
Go to the documentation of this file.
1/*
2* Integer Rounding Functions
3* (C) 1999-2007 Jack Lloyd
4*
5* Distributed under the terms of the Botan license
6*/
7
8#ifndef BOTAN_ROUNDING_H__
9#define BOTAN_ROUNDING_H__
10
11#include <botan/types.h>
12
13namespace Botan {
14
15/**
16* Round up
17* @param n an integer
18* @param align_to the alignment boundary
19* @return n rounded up to a multiple of align_to
20*/
21template<typename T>
22inline T round_up(T n, T align_to)
23 {
24 if(n % align_to || n == 0)
25 n += align_to - (n % align_to);
26 return n;
27 }
28
29/**
30* Round down
31* @param n an integer
32* @param align_to the alignment boundary
33* @return n rounded down to a multiple of align_to
34*/
35template<typename T>
36inline T round_down(T n, T align_to)
37 {
38 return (n - (n % align_to));
39 }
40
41}
42
43#endif
T round_up(T n, T align_to)
Definition rounding.h:22
T round_down(T n, T align_to)
Definition rounding.h:36