log_2.hpp 1.12 KB
Newer Older
1
// Software License for MTL
2
//
3
4
5
6
7
// Copyright (c) 2007 The Trustees of Indiana University.
//               2008 Dresden University of Technology and the Trustees of Indiana University.
//               2010 SimuNova UG (haftungsbeschränkt), www.simunova.com.
// All rights reserved.
// Authors: Peter Gottschling and Andrew Lumsdaine
8
//
9
// This file is part of the Matrix Template Library
10
//
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// See also license.mtl.txt in the distribution.

#ifndef META_MATH_LOG_2_INCLUDE
#define META_MATH_LOG_2_INCLUDE

#include <boost/numeric/meta_math/is_power_of_2.hpp>

namespace meta_math {

// Computes the logarithm to the basis 2
// Without testing if power of 2 it rounds values down to next integer
template <unsigned long X>
struct log_2
{
    // BOOST_STATIC_ASSERT(is_power_of_2_meta<X>::value);
    static const unsigned long tmp= X >> 1, value= log_2<tmp>::value + 1;
};

template <> struct log_2<1>
{
    static const unsigned long value= 0;
};

template <> struct log_2<0>
{
  // #error "Logarithm of 0 is undefined"
  BOOST_STATIC_ASSERT(true); // Logarithm of 0 is undefined
};


} // namespace meta_math

#endif // META_MATH_LOG_2_INCLUDE