Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
integer_log2.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/math/integer_log2.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 /******************************************************************************/
16 
17 unsigned integer_log2_floor(int i) {
19 }
20 
21 unsigned integer_log2_floor(unsigned int i) {
23 }
24 
25 unsigned integer_log2_floor(long i) {
27 }
28 
29 unsigned integer_log2_floor(unsigned long i) {
31 }
32 
33 unsigned integer_log2_floor(long long i) {
35 }
36 
37 unsigned integer_log2_floor(unsigned long long i) {
39 }
40 
41 /******************************************************************************/
42 
43 unsigned integer_log2_ceil(int i) {
44  if (i <= 1) return 0;
45  return integer_log2_floor(i - 1) + 1;
46 }
47 
48 unsigned integer_log2_ceil(unsigned int i) {
49  if (i <= 1) return 0;
50  return integer_log2_floor(i - 1) + 1;
51 }
52 
53 unsigned integer_log2_ceil(long i) {
54  if (i <= 1) return 0;
55  return integer_log2_floor(i - 1) + 1;
56 }
57 
58 unsigned integer_log2_ceil(unsigned long i) {
59  if (i <= 1) return 0;
60  return integer_log2_floor(i - 1) + 1;
61 }
62 
63 unsigned integer_log2_ceil(long long i) {
64  if (i <= 1) return 0;
65  return integer_log2_floor(i - 1) + 1;
66 }
67 
68 unsigned integer_log2_ceil(unsigned long long i) {
69  if (i <= 1) return 0;
70  return integer_log2_floor(i - 1) + 1;
71 }
72 
73 } // namespace tlx
74 
75 /******************************************************************************/
static unsigned integer_log2_floor_template(IntegerType i)
calculate the log2 floor of an integer type (by repeated bit shifts)
unsigned integer_log2_floor(int i)
calculate the log2 floor of an integer type (by repeated bit shifts)
unsigned integer_log2_ceil(int i)
calculate the log2 ceiling of an integer type (by repeated bit shifts)