From: Nick Bowler Date: Sun, 7 Jan 2024 03:14:42 +0000 (-0500) Subject: Improve RNG compatibility with old compilers. X-Git-Url: http://git.draconx.ca/gitweb/rrace.git/commitdiff_plain/1cc5fc775e2a5dbd41cb968fa141be6647d1282a Improve RNG compatibility with old compilers. 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. --- diff --git a/src/game.c b/src/game.c index ab70478..8016251 100644 --- a/src/game.c +++ b/src/game.c @@ -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 #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); }