bzr branch
http://suren.me/webbzr/ani/mrses
1
by Suren A. Chilingaryan
Initial import |
1 |
#ifndef _TOOLS_H
|
2 |
#define _TOOLS_H
|
|
3 |
||
4 |
||
5 |
#define isqrt(a) ((a<0)?(-sqrt(-a)):sqrt(a))
|
|
6 |
#define max(a,b) (((a)>(b))?(a):(b))
|
|
7 |
#define min(a,b) (((a)<(b))?(a):(b))
|
|
8 |
#define rnd(i) ((int)((i) * (random() / (RAND_MAX + 1.0))))
|
|
9 |
#define calc_alloc(size,rounding) ((((size)/(rounding)) + (((size)%(rounding))?1:0))*(rounding))
|
|
10 |
||
11 |
#define lcm(x, y) ((x * y) / gcd(x, y))
|
|
12 |
#define lcm3(x, y, z) lcm(lcm(x, y), z)
|
|
13 |
||
14 |
#define SWAPij(index, i, j) { \
|
|
15 |
int tmp = *(index+i); *(index+i) = *(index+j); *(index+j) = tmp; \
|
|
16 |
}
|
|
17 |
#define SWAPi(index, properties, i) { \
|
|
18 |
int tmp1 = rnd(properties); \
|
|
19 |
SWAPij(index, i, tmp1); \
|
|
20 |
}
|
|
21 |
#define SWAP(index, properties, width) { \
|
|
22 |
int tmp1 = rnd(properties - width); \
|
|
23 |
int tmp2 = rnd(width); \
|
|
24 |
SWAPij(index, tmp2, width + tmp1); \
|
|
25 |
}
|
|
26 |
||
27 |
#define PRINT_MATRIX(fmt, MATRIX, width, n, m) \
|
|
28 |
{ \
|
|
29 |
int i, j; \
|
|
30 |
for (i = 0; i < n; i++) { \
|
|
31 |
for (j = 0; j < m; j++) \
|
|
32 |
printf(fmt, MATRIX[i * width + j]); \
|
|
33 |
printf("\n"); \
|
|
34 |
} \
|
|
35 |
printf("\n"); \
|
|
36 |
}
|
|
37 |
||
38 |
#define PRINT_MULTIMATRIX(num, fmt, MATRIX, width, n, m) \
|
|
39 |
{ \
|
|
40 |
int i, j; \
|
|
41 |
for (i = 0; i < n; i++) { \
|
|
42 |
for (j = 0; j < m; j++) \
|
|
43 |
printf(fmt, MATRIX[4*(i * width + j) + num]); \
|
|
44 |
printf("\n"); \
|
|
45 |
} \
|
|
46 |
printf("\n"); \
|
|
47 |
}
|
|
48 |
||
49 |
||
50 |
||
51 |
unsigned gcd(unsigned x, unsigned y); |
|
52 |
||
53 |
||
54 |
#endif /* _TOOLS_H */ |