NFFT
3.3.0
Main Page
Modules
Data Structures
Files
File List
Globals
kernel
util
int.c
1
/*
2
* Copyright (c) 2002, 2015 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 Y(exp2i)(
const
INT a)
24
{
25
return
(1U << a);
26
}
27
28
INT Y(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 Y(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
if
(N == 1)
51
return
2;
52
else
53
{
54
n = N;
55
logn = 0;
56
while
(n != 1)
57
{
58
if
(n%2 == 1)
59
N_is_not_power_of_2=1;
60
n = n/2;
61
logn++;
62
}
63
64
if
(!N_is_not_power_of_2)
65
logn--;
66
67
for
(i = 0; i <= logn; i++)
68
n = n*2;
69
70
return
n;
71
}
72
}
73
76
void
Y(next_power_of_2_exp)(
const
INT N, INT *N2, INT *t)
77
{
78
INT n,i,logn;
79
INT N_is_not_power_of_2=0;
80
81
if
(N == 0)
82
{
83
*N2 = 1;
84
*t = 0;
85
}
86
else
87
{
88
n = N;
89
logn = 0;
90
while
(n != 1)
91
{
92
if
(n%2 == 1)
93
{
94
N_is_not_power_of_2=1;
95
}
96
n = n/2;
97
logn++;
98
}
99
100
if
(!N_is_not_power_of_2)
101
{
102
logn--;
103
}
104
105
for
(i = 0; i <= logn; i++)
106
{
107
n = n*2;
108
}
109
110
*N2 = n;
111
*t = logn+1;
112
}
113
}
Generated by
1.8.9.1