summaryrefslogtreecommitdiffhomepage
path: root/misc/examples
diff options
context:
space:
mode:
authortylov <[email protected]>2023-07-09 00:06:54 +0200
committertylov <[email protected]>2023-07-10 19:31:41 +0200
commit071b41c0fe95cb3f9a72bbe0417d856e7989ca08 (patch)
tree41714c18e813b4eeec48f7d5a7109485f097f5d5 /misc/examples
parentc773d8b1f41d5c2ceb228c44a9958e22db0990e2 (diff)
downloadSTC-modified-071b41c0fe95cb3f9a72bbe0417d856e7989ca08.tar.gz
STC-modified-071b41c0fe95cb3f9a72bbe0417d856e7989ca08.zip
Backport from dev43: Bugfixes on 4.2 from raspberry pi 32-bit testing. Fixes issue #61: too small int used in example.
Diffstat (limited to 'misc/examples')
-rwxr-xr-xmisc/examples/make.sh2
-rw-r--r--misc/examples/prime.c20
-rw-r--r--misc/examples/queue.c2
-rw-r--r--misc/examples/random.c2
4 files changed, 14 insertions, 12 deletions
diff --git a/misc/examples/make.sh b/misc/examples/make.sh
index 0297e5a1..b0c0bd52 100755
--- a/misc/examples/make.sh
+++ b/misc/examples/make.sh
@@ -6,7 +6,7 @@ if [ "$(uname)" = 'Linux' ]; then
oflag='-o '
fi
-cc=gcc; cflags="-s -O3 -std=c99 -Wconversion -Wpedantic -Wall -Wsign-compare -Wwrite-strings"
+cc=gcc; cflags="-s -O3 -std=c99 -Wconversion -Wpedantic -Wall -Wsign-compare -Wwrite-strings -Wno-maybe-uninitialized"
#cc=gcc; cflags="-g -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall $sanitize"
#cc=tcc; cflags="-Wall -std=c99"
#cc=clang; cflags="-s -O2 -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall -Wno-unused-function -Wsign-compare -Wwrite-strings"
diff --git a/misc/examples/prime.c b/misc/examples/prime.c
index d0887353..c3a0663c 100644
--- a/misc/examples/prime.c
+++ b/misc/examples/prime.c
@@ -5,20 +5,22 @@
#include <stc/algo/filter.h>
#include <stc/algo/crange.h>
+typedef long long llong;
-cbits sieveOfEratosthenes(int64_t n)
+
+cbits sieveOfEratosthenes(llong n)
{
cbits bits = cbits_with_size(n/2 + 1, true);
- int64_t q = (int64_t)sqrt((double) n) + 1;
- for (int64_t i = 3; i < q; i += 2) {
- int64_t j = i;
+ llong q = (llong)sqrt((double) n) + 1;
+ for (llong i = 3; i < q; i += 2) {
+ llong j = i;
for (; j < n; j += 2) {
if (cbits_test(&bits, j>>1)) {
i = j;
break;
}
}
- for (int64_t j = i*i; j < n; j += i*2)
+ for (llong j = i*i; j < n; j += i*2)
cbits_reset(&bits, j>>1);
}
return bits;
@@ -26,15 +28,15 @@ cbits sieveOfEratosthenes(int64_t n)
int main(void)
{
- int64_t n = 1000000000;
- printf("Computing prime numbers up to %" c_ZI "\n", n);
+ llong n = 100000000;
+ printf("Computing prime numbers up to %lld\n", n);
clock_t t1 = clock();
cbits primes = sieveOfEratosthenes(n + 1);
- int64_t np = cbits_count(&primes);
+ llong 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);
+ printf("Number of primes: %lld, 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)
diff --git a/misc/examples/queue.c b/misc/examples/queue.c
index 83c18d09..90c800aa 100644
--- a/misc/examples/queue.c
+++ b/misc/examples/queue.c
@@ -6,7 +6,7 @@
#include <stc/cqueue.h>
int main() {
- int n = 100000000;
+ int n = 1000000;
crand_unif_t dist;
crand_t rng = crand_init(1234);
dist = crand_unif_init(0, n);
diff --git a/misc/examples/random.c b/misc/examples/random.c
index ea9c483e..b4b437cf 100644
--- a/misc/examples/random.c
+++ b/misc/examples/random.c
@@ -4,7 +4,7 @@
int main()
{
- const size_t N = 1000000000;
+ const size_t N = 10000000;
const uint64_t seed = (uint64_t)time(NULL), range = 1000000;
crand_t rng = crand_init(seed);