aGrUM  0.16.0
pow_inl.h
Go to the documentation of this file.
1 
30 // To help IDE Parsers
31 #include <agrum/core/math/pow.h>
32 
33 namespace gum {
34  //@beforeMerging is this really faster ?
35  // Specialized pow function with integers (faster implementation).
36  INLINE unsigned long intPow(unsigned long base, unsigned long exponent) {
37  if (exponent == 0) { return 1UL; }
38 
39  unsigned long out = base;
40 
41  for (unsigned long i = 1; i < exponent; i++)
42  out *= base;
43 
44  return out;
45  }
46 
47  //@beforeMerging is this really faster ?
48  // Specialized base 2 pow function with integer.
49  INLINE unsigned long int2Pow(unsigned long exponent) { return 1UL << exponent; }
50 
51  //@beforeMerging is this really faster ?
52  // Given an integer, compute it's - superior - and closest power of two, i.e.
53  // the number of bits necessary to represent this integer as well as the
54  // maximum integer that can be represented by those bits.
55  INLINE void superiorPow(unsigned long card,
56  unsigned long& num_bits,
57  unsigned long& new_card) {
58  if (card == 0) {
59  num_bits = 0;
60  new_card = 1;
61  return;
62  }
63 
64  num_bits = 1;
65  new_card = 2;
66 
67  while (new_card < card) {
68  new_card *= 2;
69  num_bits++;
70  }
71  }
72 
73 } // namespace gum
unsigned long int2Pow(unsigned long exponent)
Specialized base 2 pow function with integer.
Definition: pow_inl.h:49
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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:55
unsigned long intPow(unsigned long base, unsigned long exponent)
Specialized pow function with integers (faster implementation).
Definition: pow_inl.h:36