diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-05 08:53:38 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-05 08:55:25 +0200 |
| commit | fd5ddb3db9f50411ca579d84f225f265ca35b56a (patch) | |
| tree | b659112cc0e2abd6c7edb08b0938c0d2de4ca066 /src/utils/math.h | |
| parent | c9e2d6466e42d6b779ac9ffa7c5ee9a9c7558df8 (diff) | |
| download | nissy-core-fd5ddb3db9f50411ca579d84f225f265ca35b56a.tar.gz nissy-core-fd5ddb3db9f50411ca579d84f225f265ca35b56a.zip | |
Rename constants from _underscore to CAPS
Diffstat (limited to '')
| -rw-r--r-- | src/utils/math.h | 52 |
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); | 6 | STATIC int64_t factorial(int64_t); |
| 7 | _static bool isperm(uint8_t *, int64_t); | 7 | STATIC bool isperm(uint8_t *, int64_t); |
| 8 | _static int64_t permtoindex(uint8_t *, int64_t); | 8 | STATIC int64_t permtoindex(uint8_t *, int64_t); |
| 9 | _static void indextoperm(int64_t, int64_t, uint8_t *); | 9 | STATIC void indextoperm(int64_t, int64_t, uint8_t *); |
| 10 | _static int permsign(uint8_t *, int64_t); | 10 | STATIC int permsign(uint8_t *, int64_t); |
| 11 | _static int64_t digitstosumzero(uint8_t *, uint8_t, uint8_t); | 11 | STATIC int64_t digitstosumzero(uint8_t *, uint8_t, uint8_t); |
| 12 | _static void sumzerotodigits(int64_t, uint8_t, uint8_t, uint8_t *); | 12 | STATIC void sumzerotodigits(int64_t, uint8_t, uint8_t, uint8_t *); |
| 13 | 13 | ||
| 14 | _static int64_t | 14 | STATIC int64_t |
| 15 | factorial(int64_t n) | 15 | factorial(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 | 34 | STATIC bool |
| 35 | isperm(uint8_t *a, int64_t n) | 35 | isperm(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 | 62 | STATIC int64_t |
| 63 | permtoindex(uint8_t *a, int64_t n) | 63 | permtoindex(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 | 86 | STATIC void |
| 87 | indextoperm(int64_t p, int64_t n, uint8_t *r) | 87 | indextoperm(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 | ||
| 117 | indextoperm_error: | 117 | indextoperm_error: |
| 118 | memset(r, _error, n); | 118 | memset(r, UINT8_ERROR, n); |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | _static int | 121 | STATIC int |
| 122 | permsign(uint8_t *a, int64_t n) | 122 | permsign(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 | 134 | STATIC int64_t |
| 135 | digitstosumzero(uint8_t *a, uint8_t n, uint8_t b) | 135 | digitstosumzero(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 | 164 | STATIC void |
| 165 | sumzerotodigits(int64_t d, uint8_t n, uint8_t b, uint8_t *a) | 165 | sumzerotodigits(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 | ||
| 184 | digitstosumzero_error: | 184 | digitstosumzero_error: |
| 185 | memset(a, _error, n); | 185 | memset(a, UINT8_ERROR, n); |
| 186 | } | 186 | } |
