aboutsummaryrefslogtreecommitdiff
path: root/src/utils/math.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-09-05 08:53:38 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-09-05 08:55:25 +0200
commitfd5ddb3db9f50411ca579d84f225f265ca35b56a (patch)
treeb659112cc0e2abd6c7edb08b0938c0d2de4ca066 /src/utils/math.h
parentc9e2d6466e42d6b779ac9ffa7c5ee9a9c7558df8 (diff)
downloadnissy-core-fd5ddb3db9f50411ca579d84f225f265ca35b56a.tar.gz
nissy-core-fd5ddb3db9f50411ca579d84f225f265ca35b56a.zip
Rename constants from _underscore to CAPS
Diffstat (limited to 'src/utils/math.h')
-rw-r--r--src/utils/math.h52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/utils/math.h b/src/utils/math.h
index a361808..e6c2589 100644
--- a/src/utils/math.h
+++ b/src/utils/math.h
@@ -3,22 +3,22 @@
3#define _max(x, y) ((x) > (y) ? (x) : (y)) 3#define _max(x, y) ((x) > (y) ? (x) : (y))
4#define _div_round_up(n, d) (((n) + (d) - 1) / (d)) 4#define _div_round_up(n, d) (((n) + (d) - 1) / (d))
5 5
6_static int64_t factorial(int64_t); 6STATIC int64_t factorial(int64_t);
7_static bool isperm(uint8_t *, int64_t); 7STATIC bool isperm(uint8_t *, int64_t);
8_static int64_t permtoindex(uint8_t *, int64_t); 8STATIC int64_t permtoindex(uint8_t *, int64_t);
9_static void indextoperm(int64_t, int64_t, uint8_t *); 9STATIC void indextoperm(int64_t, int64_t, uint8_t *);
10_static int permsign(uint8_t *, int64_t); 10STATIC int permsign(uint8_t *, int64_t);
11_static int64_t digitstosumzero(uint8_t *, uint8_t, uint8_t); 11STATIC int64_t digitstosumzero(uint8_t *, uint8_t, uint8_t);
12_static void sumzerotodigits(int64_t, uint8_t, uint8_t, uint8_t *); 12STATIC void sumzerotodigits(int64_t, uint8_t, uint8_t, uint8_t *);
13 13
14_static int64_t 14STATIC int64_t
15factorial(int64_t n) 15factorial(int64_t n)
16{ 16{
17 int64_t i, ret; 17 int64_t i, ret;
18 18
19 if (n > _max_factorial) { 19 if (n > FACTORIAL_MAX) {
20 LOG("Error: won't compute factorial for n=%" PRId64 " because" 20 LOG("Error: won't compute factorial for n=%" PRId64 " because"
21 " it is larger than %" PRId64 "\n", n, _max_factorial); 21 " it is larger than %" PRId64 "\n", n, FACTORIAL_MAX);
22 return -1; 22 return -1;
23 } 23 }
24 24
@@ -31,15 +31,15 @@ factorial(int64_t n)
31 return ret; 31 return ret;
32} 32}
33 33
34_static bool 34STATIC bool
35isperm(uint8_t *a, int64_t n) 35isperm(uint8_t *a, int64_t n)
36{ 36{
37 int64_t i; 37 int64_t i;
38 bool aux[_max_factorial+1]; 38 bool aux[FACTORIAL_MAX+1];
39 39
40 if (n > _max_factorial) { 40 if (n > FACTORIAL_MAX) {
41 LOG("Error: won't compute 'isperm()' for n=%" PRId64 " because" 41 LOG("Error: won't compute 'isperm()' for n=%" PRId64 " because"
42 " it is larger than %" PRId64 "\n", n, _max_factorial); 42 " it is larger than %" PRId64 "\n", n, FACTORIAL_MAX);
43 return false; 43 return false;
44 } 44 }
45 45
@@ -59,15 +59,15 @@ isperm(uint8_t *a, int64_t n)
59 return true; 59 return true;
60} 60}
61 61
62_static int64_t 62STATIC int64_t
63permtoindex(uint8_t *a, int64_t n) 63permtoindex(uint8_t *a, int64_t n)
64{ 64{
65 int64_t i, j, c, ret; 65 int64_t i, j, c, ret;
66 66
67 if (n > _max_factorial) { 67 if (n > FACTORIAL_MAX) {
68 LOG("Error: won't compute 'permtoindex()' for n=%" PRId64 68 LOG("Error: won't compute 'permtoindex()' for n=%" PRId64
69 " because it is larger than %" PRId64 "\n", 69 " because it is larger than %" PRId64 "\n",
70 n, _max_factorial); 70 n, FACTORIAL_MAX);
71 return -1; 71 return -1;
72 } 72 }
73 73
@@ -83,16 +83,16 @@ permtoindex(uint8_t *a, int64_t n)
83 return ret; 83 return ret;
84} 84}
85 85
86_static void 86STATIC void
87indextoperm(int64_t p, int64_t n, uint8_t *r) 87indextoperm(int64_t p, int64_t n, uint8_t *r)
88{ 88{
89 int64_t i, j, c; 89 int64_t i, j, c;
90 uint8_t a[_max_factorial+1]; 90 uint8_t a[FACTORIAL_MAX+1];
91 91
92 if (n > _max_factorial) { 92 if (n > FACTORIAL_MAX) {
93 LOG("Error: won't compute 'permtoindex()' for n=%" PRId64 93 LOG("Error: won't compute 'permtoindex()' for n=%" PRId64
94 " because it is larger than %" PRId64 "\n", 94 " because it is larger than %" PRId64 "\n",
95 n, _max_factorial); 95 n, FACTORIAL_MAX);
96 goto indextoperm_error; 96 goto indextoperm_error;
97 } 97 }
98 98
@@ -115,10 +115,10 @@ indextoperm(int64_t p, int64_t n, uint8_t *r)
115 return; 115 return;
116 116
117indextoperm_error: 117indextoperm_error:
118 memset(r, _error, n); 118 memset(r, UINT8_ERROR, n);
119} 119}
120 120
121_static int 121STATIC int
122permsign(uint8_t *a, int64_t n) 122permsign(uint8_t *a, int64_t n)
123{ 123{
124 int i, j; 124 int i, j;
@@ -131,7 +131,7 @@ permsign(uint8_t *a, int64_t n)
131 return ret % 2; 131 return ret % 2;
132} 132}
133 133
134_static int64_t 134STATIC int64_t
135digitstosumzero(uint8_t *a, uint8_t n, uint8_t b) 135digitstosumzero(uint8_t *a, uint8_t n, uint8_t b)
136{ 136{
137 int64_t ret, p; 137 int64_t ret, p;
@@ -161,7 +161,7 @@ digitstosumzero(uint8_t *a, uint8_t n, uint8_t b)
161 return ret; 161 return ret;
162} 162}
163 163
164_static void 164STATIC void
165sumzerotodigits(int64_t d, uint8_t n, uint8_t b, uint8_t *a) 165sumzerotodigits(int64_t d, uint8_t n, uint8_t b, uint8_t *a)
166{ 166{
167 uint8_t sum; 167 uint8_t sum;
@@ -182,5 +182,5 @@ sumzerotodigits(int64_t d, uint8_t n, uint8_t b, uint8_t *a)
182 return; 182 return;
183 183
184digitstosumzero_error: 184digitstosumzero_error:
185 memset(a, _error, n); 185 memset(a, UINT8_ERROR, n);
186} 186}

Generated with cgit - Back to sebastiano.tronto.net