diff options
| author | Tyge Løvset <[email protected]> | 2023-08-01 18:12:01 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-08-01 18:12:01 +0200 |
| commit | 7df124507b82bfb168a440392060bc0e03ce5c7e (patch) | |
| tree | 259e737ec25e4fb916f50132cf96cd6d06f131b3 | |
| parent | 94391527ef50cbee073a4b427f6fe839c010ecb1 (diff) | |
| download | STC-modified-7df124507b82bfb168a440392060bc0e03ce5c7e.tar.gz STC-modified-7df124507b82bfb168a440392060bc0e03ce5c7e.zip | |
Fixed conversion warnings.
| -rw-r--r-- | misc/examples/algorithms/random.c | 35 | ||||
| -rw-r--r-- | misc/examples/mixed/demos.c | 6 |
2 files changed, 19 insertions, 22 deletions
diff --git a/misc/examples/algorithms/random.c b/misc/examples/algorithms/random.c index 9522c16d..e457d329 100644 --- a/misc/examples/algorithms/random.c +++ b/misc/examples/algorithms/random.c @@ -4,42 +4,39 @@ int main(void) { - const long long N = 10000000; - const uint64_t seed = (uint64_t)time(NULL), range = 1000000; + const long long N = 10000000, range = 1000000; + const uint64_t seed = (uint64_t)time(NULL); crand_t rng = crand_init(seed); - - long long sum; - clock_t diff, before; + clock_t t; printf("Compare speed of full and unbiased ranged random numbers...\n"); - sum = 0; - before = clock(); + long long sum = 0; + t = clock(); c_forrange (N) { - sum += (uint32_t)crand_u64(&rng); + sum += (int32_t)crand_u64(&rng); } - diff = clock() - before; + t = clock() - t; printf("full range\t\t: %f secs, %lld, avg: %f\n", - (double)diff/(double)CLOCKS_PER_SEC, N, (double)(sum/N)); + (double)t/CLOCKS_PER_SEC, N, (double)(sum/N)); crand_uniform_t dist1 = crand_uniform_init(0, range); rng = crand_init(seed); sum = 0; - before = clock(); + t = clock(); c_forrange (N) { sum += crand_uniform(&rng, &dist1); // unbiased } - diff = clock() - before; + t = clock() - t; printf("unbiased 0-%lld\t: %f secs, %lld, avg: %f\n", - (long long)range, (double)diff/CLOCKS_PER_SEC, N, (double)(sum/N)); + range, (double)t/CLOCKS_PER_SEC, N, (double)(sum/N)); sum = 0; rng = crand_init(seed); - before = clock(); + t = clock(); c_forrange (N) { - sum += (int64_t)(crand_u64(&rng) % (range + 1)); // biased + sum += (int32_t)crand_u64(&rng) % (range + 1); // biased } - diff = clock() - before; - printf("biased 0-%" PRIu64 " \t: %f secs, %lld, avg: %f\n", - (long long)range, (double)diff/CLOCKS_PER_SEC, N, (double)(sum/N)); - + t = clock() - t; + printf("biased 0-%lld \t: %f secs, %lld, avg: %f\n", + range, (double)t/CLOCKS_PER_SEC, N, (double)(sum/N)); } diff --git a/misc/examples/mixed/demos.c b/misc/examples/mixed/demos.c index 1a604d9f..7f5091fd 100644 --- a/misc/examples/mixed/demos.c +++ b/misc/examples/mixed/demos.c @@ -28,7 +28,7 @@ void stringdemo1(void) cstr_drop(&cs); } -#define i_key int64_t +#define i_key long long #define i_tag ix #include <stc/cvec.h> @@ -39,14 +39,14 @@ void vectordemo1(void) for (int i = 10; i <= 100; i += 10) cvec_ix_push(&bignums, i * i); - printf("erase - %d: %" PRIu64 "\n", 3, bignums.data[3]); + printf("erase - %d: %lld\n", 3, bignums.data[3]); cvec_ix_erase_n(&bignums, 3, 1); // erase index 3 cvec_ix_pop(&bignums); // erase the last cvec_ix_erase_n(&bignums, 0, 1); // erase the first for (int i = 0; i < cvec_ix_size(&bignums); ++i) { - printf("%d: %" PRIu64 "\n", i, bignums.data[i]); + printf("%d: %lld\n", i, bignums.data[i]); } cvec_ix_drop(&bignums); |
