Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[6db11f]: src / integer_manip.c Maximize Restore History

Download this file

integer_manip.c    189 lines (145 with data), 2.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
void fftindex(const int N, int *indexout)
{
int ii;
if (N%2==0)
{
for (ii=0;ii<N/2;ii++)
{
indexout[ii]=ii;
}
for (ii=N/2;ii<N;ii++)
{
indexout[ii]=-N+ii+1;
}
}
else
{
for (ii=0;ii<(N-1)/2;ii++)
{
indexout[ii]=ii;
}
for (ii=(N-1)/2;ii<N;ii++)
{
indexout[ii]=-N+ii+1;
}
}
}
int int_max(const int a, const int b)
{
return (a > b ? a : b);
}
int int_min(const int a, const int b)
{
return (a < b ? a : b);
}
int makelarger(const int L, const int K)
{
/* This is a floor operation */
int o = (L/K)*K;
/* Make it a ceil */
if (L%K>0)
{
o += K;
}
return o;
}
/* Extended Euclid algorithm. */
int gcd (const int a, const int b, int *r, int *s )
{
int a1 = a;
int b1 = b;
int a2 = 1;
int b2 = 0;
int a3 = 0;
int b3 = 1;
int c, d;
while ( b1 != 0 )
{
d=a1/b1;
c = a1;
a1 = b1;
b1 = c-d*b1;
c = a2;
a2 = b2;
b2 = c-d*b2;
c = a3;
a3 = b3;
b3 = c-d*b3;
}
*r=a2;
*s=a3;
return a1;
}
int lcm(const int a, const int b)
{
int junk_r, junk_s;
int c = gcd(a, b, &junk_r, &junk_s);
return (a*b/c);
}
void gabimagepars(const int Ls, const int x, const int y,
int *a, int *M, int *L, int *N, int *Ngood)
{
*M = int_min(y,Ls);
*N = int_max(x,Ls);
/* Determine the minimum transform size. */
int K = lcm(*M,*N);
/* This L is good, but is it not the same as DGT will choose. */
int Llong = makelarger(Ls,K);
/* Fix a from the long L */
*a=Llong/(*N);
/* Now we have fixed a and M, so we can use the standard method of choosing L. */
int Lsmallest=lcm(*a,*M);
*L = makelarger(Ls, Lsmallest);
/* We did not get N as desired. */
*N=*L/(*a);
/* Number of columns to display */
*Ngood=(Ls/(*a));
}
/* Determine the size of the output array of wfacreal and iwfacreal */
int wfacreal_size(const int L, const int a, const int M)
{
int h_a, h_m;
const int b=L/M;
const int c=gcd(a, M,&h_a, &h_m);
const int p=a/c;
const int d=b/p;
/* This is a floor operation. */
const int d2= d/2+1;
return d2*p*M;
}
size_t nextPow2_st(size_t x)
{
size_t bits = sizeof(x)*8;
if(x==0)
return 1;
x--;
(x) = ((x)>>1) | (x);
(x) = ((x)>>2) | (x);
(x) = ((x)>>4) | (x);
(x) = ((x)>>8) | (x);
(x) = ((x)>>16) | (x);
if(bits>32)
(x) = ((x)>>32) | (x);
(x)++;
return x;
}
size_t nextfastfft(size_t x)
{
while (1) {
ptrdiff_t m = x;
while ((m % 2) == 0)
m /= 2;
while ((m % 3) == 0)
m /= 3;
while ((m % 5) == 0)
m /= 5;
if (m <= 1)
break; /* n is completely factorable by twos, threes, and fives */
x++;
}
return x;
}