NFFT Logo 3.2.3
int.c
1 /*
2  * Copyright (c) 2002, 2012 Jens Keiner, Stefan Kunis, Daniel Potts
3  *
4  * This program is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  * details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc., 51
16  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 /* $Id: util.c 3483 2010-04-23 19:02:34Z keiner $ */
20 
21 #include "infft.h"
22 
23 int X(exp2i)(const int a)
24 {
25  return (1U << a);
26 }
27 
28 int X(log2i)(const int m)
29 {
30  int l = 0;
31  int mm = m;
32 
33  while (mm > 0)
34  {
35  mm = (mm >> 1);
36  l++;
37  }
38  return (l-1);
39 }
40 
43 int X(next_power_of_2)(const int N)
44 {
45  int n,i,logn;
46  int N_is_not_power_of_2=0;
47 
48  if (N == 0)
49  return 1;
50  else
51  {
52  n = N;
53  logn = 0;
54  while (n != 1)
55  {
56  if (n%2 == 1)
57  N_is_not_power_of_2=1;
58  n = n/2;
59  logn++;
60  }
61 
62  if (!N_is_not_power_of_2)
63  logn--;
64 
65  for (i = 0; i <= logn; i++)
66  n = n*2;
67 
68  return n;
69  }
70 }
71 
74 void X(next_power_of_2_exp)(const int N, int *N2, int *t)
75 {
76  int n,i,logn;
77  int N_is_not_power_of_2=0;
78 
79  if (N == 0)
80  {
81  *N2 = 1;
82  *t = 0;
83  }
84  else
85  {
86  n=N;
87  logn=0;
88  while (n != 1)
89  {
90  if (n%2 == 1)
91  {
92  N_is_not_power_of_2=1;
93  }
94  n = n/2;
95  logn++;
96  }
97 
98  if (!N_is_not_power_of_2)
99  {
100  logn--;
101  }
102 
103  for (i = 0; i <= logn; i++)
104  {
105  n = n*2;
106  }
107 
108  *N2 = n;
109  *t = logn+1;
110  }
111 }

Generated on Tue Apr 30 2013 by Doxygen 1.8.1