GRASS GIS 8 Programmer's Manual
8.2.2dev(2023)-3d2c704037
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
}
gmath.h
G_math_max_pow2
long G_math_max_pow2(const long n)
Finds least power of 2 >= n
Definition:
max_pow2.c:16
gis.h
G_math_min_pow2
long G_math_min_pow2(const long n)
Finds largest power of 2 <= n
Definition:
max_pow2.c:44
lib
gmath
max_pow2.c
Generated on Tue Feb 14 2023 05:56:00 for GRASS GIS 8 Programmer's Manual by
1.8.13