tlx
Loading...
Searching...
No Matches
log2.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 * tlx/meta/log2.hpp
3 *
4 * Template Metaprogramming Tools (from the Generative Programming book Krysztof
5 * Czarnecki, Ulrich Eisenecker)
6 *
7 * Part of tlx - http://panthema.net/tlx
8 *
9 * Copyright (C) 2003 Roman Dementiev <dementiev@mpi-sb.mpg.de>
10 * Copyright (C) 2008 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
11 * Copyright (C) 2010-2017 Timo Bingmann <tb@panthema.net>
12 *
13 * All rights reserved. Published under the Boost Software License, Version 1.0
14 ******************************************************************************/
15
16#ifndef TLX_META_LOG2_HEADER
17#define TLX_META_LOG2_HEADER
18
19#include <cstdint>
20
21namespace tlx {
22
23//! \addtogroup tlx_meta
24//! \{
25
26/******************************************************************************/
27// Log2Floor<Value>::value
28
29template <uint64_t Input>
31{
32public:
33 enum {
34 value = Log2Floor<Input / 2>::value + 1
35 };
36};
37
38template <>
39class Log2Floor<1>
40{
41public:
42 enum { value = 0 };
43};
44
45template <>
46class Log2Floor<0>
47{
48public:
49 enum { value = 0 };
50};
51
52/******************************************************************************/
53// Log2<Value>::floor and Log2<Value>::ceil
54
55template <uint64_t Input>
56class Log2
57{
58public:
59 enum {
61 ceil = Log2Floor<Input - 1>::value + 1
62 };
63};
64
65template <>
66class Log2<1>
67{
68public:
69 enum {
70 floor = 0,
71 ceil = 0
72 };
73};
74
75template <>
76class Log2<0>
77{
78public:
79 enum {
80 floor = 0,
81 ceil = 0
82 };
83};
84
85//! \}
86
87} // namespace tlx
88
89#endif // !TLX_META_LOG2_HEADER
90
91/******************************************************************************/
@ ceil
Definition: log2.hpp:61
@ floor
Definition: log2.hpp:60