tlx
is_power_of_two.hpp
Go to the documentation of this file.
1/*******************************************************************************
2 * tlx/math/is_power_of_two.hpp
3 *
4 * Part of tlx - http://panthema.net/tlx
5 *
6 * Copyright (C) 2007-2018 Timo Bingmann <tb@panthema.net>
7 *
8 * All rights reserved. Published under the Boost Software License, Version 1.0
9 ******************************************************************************/
10
11#ifndef TLX_MATH_IS_POWER_OF_TWO_HEADER
12#define TLX_MATH_IS_POWER_OF_TWO_HEADER
13
14namespace tlx {
15
16//! \addtogroup tlx_math
17//! \{
18
19/******************************************************************************/
20
21template <typename Integral>
22static inline bool is_power_of_two_template(Integral i) {
23 if (i <= 0) return false;
24 return !(i & (i - 1));
25}
26
27/******************************************************************************/
28// is_power_of_two()
29
30//! does what it says: true if i is a power of two
31static inline bool is_power_of_two(int i) {
33}
34
35//! does what it says: true if i is a power of two
36static inline bool is_power_of_two(unsigned int i) {
38}
39
40//! does what it says: true if i is a power of two
41static inline bool is_power_of_two(long i) {
43}
44
45//! does what it says: true if i is a power of two
46static inline bool is_power_of_two(unsigned long i) {
48}
49
50//! does what it says: true if i is a power of two
51static inline bool is_power_of_two(long long i) {
53}
54
55//! does what it says: true if i is a power of two
56static inline bool is_power_of_two(unsigned long long i) {
58}
59
60//! \}
61
62} // namespace tlx
63
64#endif // !TLX_MATH_IS_POWER_OF_TWO_HEADER
65
66/******************************************************************************/
static bool is_power_of_two(int i)
does what it says: true if i is a power of two
static bool is_power_of_two_template(Integral i)