Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
is_power_of_two.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/math/is_power_of_two.cpp
3  *
4  * Part of tlx - http://panthema.net/tlx
5  *
6  * Copyright (C) 2007-2017 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the Boost Software License, Version 1.0
9  ******************************************************************************/
10 
12 
13 namespace tlx {
14 
15 template <typename Integral>
16 static inline bool is_power_of_two_template(Integral i) {
17  if (i <= 0) return false;
18  return !(i & (i - 1));
19 }
20 
21 /******************************************************************************/
22 
23 bool is_power_of_two(int i) {
24  return is_power_of_two_template(i);
25 }
26 
27 bool is_power_of_two(unsigned int i) {
28  return is_power_of_two_template(i);
29 }
30 
31 bool is_power_of_two(long i) {
32  return is_power_of_two_template(i);
33 }
34 
35 bool is_power_of_two(unsigned long i) {
36  return is_power_of_two_template(i);
37 }
38 
39 bool is_power_of_two(long long i) {
40  return is_power_of_two_template(i);
41 }
42 
43 bool is_power_of_two(unsigned long long i) {
44  return is_power_of_two_template(i);
45 }
46 
47 } // namespace tlx
48 
49 /******************************************************************************/
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)