]> git.draconx.ca Git - cdecl99.git/commitdiff
tests: Improve RNG compatibility with old compilers.
authorNick Bowler <nbowler@draconx.ca>
Sun, 7 Jan 2024 01:42:03 +0000 (20:42 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sun, 7 Jan 2024 01:48:51 +0000 (20:48 -0500)
Some C89 compilers with 32-bit longs won't automatically widen integer
constants to (unsigned) long long in order to represent values that
don't fit in an (unsigned) long, even if those compilers otherwise
support 64-bit long long.

The "ll" and "ull" suffixes seem to get things working.

t/rng.c

diff --git a/t/rng.c b/t/rng.c
index 2e2fc09ebfe15c48edae62e304a11f0cfbc831b0..e442d994fe5cbcd2fef22930e7ed133d3727e76a 100644 (file)
--- a/t/rng.c
+++ b/t/rng.c
@@ -32,7 +32,7 @@
 #  include "test.h"
 #endif
 
-#define B64(x) ((x) & 0xffffffffffffffff)
+#define B64(x) ((x) & 0xffffffffffffffffull)
 
 struct test_rng {
        unsigned long long state[4];
@@ -65,9 +65,9 @@ static unsigned long long splitmix64(unsigned long long *state)
 {
        unsigned long long z;
 
-       z = B64(*state += 0x9e3779b97f4a7c15);
-       z = B64((z ^ (z >> 30)) * 0xbf58476d1ce4e5b9);
-       z = B64((z ^ (z >> 27)) * 0x94d049bb133111eb);
+       z = B64(*state += 0x9e3779b97f4a7c15ull);
+       z = B64((z ^ (z >> 30)) * 0xbf58476d1ce4e5b9ull);
+       z = B64((z ^ (z >> 27)) * 0x94d049bb133111ebull);
 
        return z ^ (z >> 31);
 }