GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72846
max_pow2.c
Go to the documentation of this file.
1 #include <grass/gis.h>
2 #include <grass/gmath.h>
3
4
5 /*!
6  * \fn long G_math_max_pow2 (const long n)
7  *
8  * \brief Finds least power of 2 >= <b>n</b>
9  *
10  * Finds least power of 2 >= <b>n</b>.
11  *
12  * \param[in] n
13  * \return long
14  */
15
16 long G_math_max_pow2(const long n)
17 {
18  long p2, n1;
19
20  n1 = n >> 1;
21  p2 = 1;
22  while (n1 > 0) {
23  n1 >>= 1;
24  p2 <<= 1;
25  }
26  if (p2 < n)
27  p2 <<= 1;
28
29  return (p2);
30 }
31
32
33 /*!
34  * \fn long G_math_min_pow2 (const long n)
35  *
36  * \brief Finds largest power of 2 <= <b>n</b>
37  *
38  * Finds largest power of 2 <= <b>n</b>.
39  *
40  * \param[in] n
41  * \return long
42  */
43
44 long G_math_min_pow2(const long n)
45 {
46  long p2, n1;
47
48  n1 = n >> 1;
49  p2 = 1;
50  while (n1 > 0) {
51  n1 >>= 1;
52  p2 <<= 1;
53  }
54
55  return (p2);
56 }
long G_math_max_pow2(const long n)
Finds least power of 2 &gt;= n
Definition: max_pow2.c:16
long G_math_min_pow2(const long n)
Finds largest power of 2 &lt;= n
Definition: max_pow2.c:44