diff options
| author | Ethan Werner <mail@ethanwerner.com> | 2026-08-09 15:02:21 +0400 |
|---|---|---|
| committer | Ethan Werner <mail@ethanwerner.com> | 2026-08-09 15:02:21 +0400 |
| commit | 3d92926a902017e7cf1f5738e99ff62da596ce12 (patch) | |
| tree | 2b55422c26a48759d56fa91f06df24449e9dfa88 /main.c | |
| parent | 07e18043145f3d91c8ea7ec3ad41b3c905585277 (diff) | |
Diffstat (limited to 'main.c')
| -rwxr-xr-x | main.c | 19 |
1 files changed, 3 insertions, 16 deletions
@@ -41,17 +41,8 @@ int main(int argc, char *argv[]) { } period = (uint_t)val; } - if (period == 0 || period > BUFFER_SIZE) { - fprintf(stderr, "Error: period must be between 1 and %d\n", BUFFER_SIZE); - usage(argv[0]); - return 1; - } - fp_t input[BUFFER_SIZE]; fp_t output[BUFFER_SIZE]; - for (int_t i = 0; i < (int_t)BUFFER_SIZE; i++) { - output[i] = 0; - } if (!ts_fill(input, BUFFER_SIZE, 0, (fp_t)BUFFER_SIZE)) { fprintf(stderr, "ts_fill failed\n"); @@ -63,19 +54,15 @@ int main(int argc, char *argv[]) { ts_constant_t c; memset(&c, 0, sizeof(c)); - *(uint_t *)c.data = period; + memcpy(c.data, &period, sizeof(period)); int ret = ts_average(y, 1, x, 1, BUFFER_SIZE, &c); if (ret == -1) { fprintf(stderr, "ts_average failed\n"); return 1; } - /* Validate output: first valid value is at index period-1 */ + /* First valid SMA value is at index period-1 */ uint_t offset = period - 1; - if (offset >= BUFFER_SIZE) { - fprintf(stderr, "error: period exceeds buffer size\n"); - return 1; - } /* Clamp display range to valid output */ uint_t display_end = DISPLAY_N < BUFFER_SIZE ? DISPLAY_N : BUFFER_SIZE; @@ -85,7 +72,7 @@ int main(int argc, char *argv[]) { } for (uint_t i = offset; i < display_end; i++) { - printf("input[%" TS_PRIuint "] = %f SMA[%" TS_PRIuint "] = %f\n", i, input[i], i, output[i]); + printf("input[%" TS_PRIuint "] = %" TS_PRIfp " SMA[%" TS_PRIuint "] = %" TS_PRIfp "\n", i, input[i], i, output[i]); } return 0; |