aGrUM  0.13.2
pow_inl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN and Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 // To help IDE Parsers
28 #include <agrum/core/math/pow.h>
29
30 namespace gum {
31  //@beforeMerging is this really faster ?
32  // Specialized pow function with integers (faster implementation).
33  INLINE unsigned long intPow(unsigned long base, unsigned long exponent) {
34  if (exponent == 0) { return 1UL; }
35
36  unsigned long out = base;
37
38  for (unsigned long i = 1; i < exponent; i++)
39  out *= base;
40
41  return out;
42  }
43
44  //@beforeMerging is this really faster ?
45  // Specialized base 2 pow function with integer.
46  INLINE unsigned long int2Pow(unsigned long exponent) { return 1UL << exponent; }
47
48  //@beforeMerging is this really faster ?
49  // Given an integer, compute it's - superior - and closest power of two, i.e.
50  // the number of bits necessary to represent this integer as well as the
51  // maximum integer that can be represented by those bits.
52  INLINE void superiorPow(unsigned long card,
53  unsigned long& num_bits,
54  unsigned long& new_card) {
55  if (card == 0) {
56  num_bits = 0;
57  new_card = 1;
58  return;
59  }
60
61  num_bits = 1;
62  new_card = 2;
63
64  while (new_card < card) {
65  new_card *= 2;
66  num_bits++;
67  }
68  }
69
70 } // namespace gum
unsigned long int2Pow(unsigned long exponent)
Specialized base 2 pow function with integer.
Definition: pow_inl.h:46
Implementation of pow functions with integers, faster than stl implementation.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
void superiorPow(unsigned long card, unsigned long &num_bits, unsigned long &new_card)
Compute the superior and closest power of two of an integer.
Definition: pow_inl.h:52
unsigned long intPow(unsigned long base, unsigned long exponent)
Specialized pow function with integers (faster implementation).
Definition: pow_inl.h:33