GRASS Programmer's Manual  6.4.2(2012)
max_pow2.c
Go to the documentation of this file.
00001 #include <grass/gis.h>
00002 #include <grass/gmath.h>
00003 
00004 
00016 long G_math_max_pow2(const long n)
00017 {
00018     long p2, n1;
00019 
00020     n1 = n >> 1;
00021     p2 = 1;
00022     while (n1 > 0) {
00023         n1 >>= 1;
00024         p2 <<= 1;
00025     }
00026     if (p2 < n)
00027         p2 <<= 1;
00028 
00029     return (p2);
00030 }
00031 
00032 
00044 long G_math_min_pow2(const long n)
00045 {
00046     long p2, n1;
00047 
00048     n1 = n >> 1;
00049     p2 = 1;
00050     while (n1 > 0) {
00051         n1 >>= 1;
00052         p2 <<= 1;
00053     }
00054 
00055     return (p2);
00056 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines