diff options
| author | Tyge Løvset <[email protected]> | 2023-03-26 00:27:45 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-03-26 00:27:45 +0100 |
| commit | eb85069b669e754836b9d4587ba03d3af1a5e975 (patch) | |
| tree | 45c9a0d3fe40c59a8b33ae8ecd2e7aa78bef6240 /misc/examples/prime.c | |
| parent | e8be14dfc894eeac859f0287d4d5b4f4745c0585 (diff) | |
| download | STC-modified-eb85069b669e754836b9d4587ba03d3af1a5e975.tar.gz STC-modified-eb85069b669e754836b9d4587ba03d3af1a5e975.zip | |
development branch for 4.2
Removed uses of c_auto and c_with in documentation examples and code examples. Still using c_defer a few places.
Renamed c11/fmt.h to c11/print.h.
Some additions in ccommon.h, e.g. c_const_cast(T, x).
Improved docs.
Diffstat (limited to 'misc/examples/prime.c')
| -rw-r--r-- | misc/examples/prime.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/misc/examples/prime.c b/misc/examples/prime.c index 16a59774..18bf3490 100644 --- a/misc/examples/prime.c +++ b/misc/examples/prime.c @@ -30,24 +30,25 @@ int main(void) printf("Computing prime numbers up to %" c_ZI "\n", n); clock_t t1 = clock(); - c_with (cbits primes = sieveOfEratosthenes(n + 1), cbits_drop(&primes)) { - int64_t np = cbits_count(&primes); - clock_t t2 = clock(); + cbits primes = sieveOfEratosthenes(n + 1); + int64_t np = cbits_count(&primes); + clock_t t2 = clock(); - printf("Number of primes: %" c_ZI ", time: %f\n\n", np, (float)(t2 - t1) / (float)CLOCKS_PER_SEC); - puts("Show all the primes in the range [2, 1000):"); - printf("2"); - c_forrange (i, 3, 1000, 2) - if (cbits_test(&primes, i>>1)) printf(" %lld", i); - puts("\n"); + printf("Number of primes: %" c_ZI ", time: %f\n\n", np, (float)(t2 - t1) / (float)CLOCKS_PER_SEC); + puts("Show all the primes in the range [2, 1000):"); + printf("2"); + c_forrange (i, 3, 1000, 2) + if (cbits_test(&primes, i>>1)) printf(" %lld", i); + puts("\n"); - puts("Show the last 50 primes using a temporary crange generator:"); - crange R = crange_make(n - 1, 0, -2); - c_forfilter (i, crange, R, - cbits_test(&primes, *i.ref>>1) && - c_flt_take(i, 50)) { - printf("%lld ", *i.ref); - if (c_flt_last(i) % 10 == 0) puts(""); - } + puts("Show the last 50 primes using a temporary crange generator:"); + crange R = crange_make(n - 1, 0, -2); + c_forfilter (i, crange, R, + cbits_test(&primes, *i.ref>>1) && + c_flt_take(i, 50)) { + printf("%lld ", *i.ref); + if (c_flt_last(i) % 10 == 0) puts(""); } + + cbits_drop(&primes); } |
