]> git.draconx.ca Git - rrace.git/commitdiff
Improve RNG compatibility with old compilers.
authorNick Bowler <nbowler@draconx.ca>
Sun, 7 Jan 2024 03:14:42 +0000 (22:14 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sun, 7 Jan 2024 03:22:28 +0000 (22:22 -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.

src/game.c

index ab704789e8c483fb37715a14bdfa8cb1809f85e8..801625103ab9ef09ae747a8a9b3c6447f36645a7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Slide puzzle core game logic
- * Copyright © 2022-2023 Nick Bowler
+ * Copyright © 2022-2024 Nick Bowler
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@
 #include <time.h>
 #include "game.h"
 
-#define B64(x) ((x) & 0xffffffffffffffff)
+#define B64(x) ((x) & 0xffffffffffffffffull)
 
 /* Rotate val left by n bits.  The behaviour is undefined if n is zero. */
 static unsigned long long rot_left64(unsigned long long val, int n)
@@ -56,9 +56,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);
 }