Untangle: replace manual int64 bodging with int64_t.

Where possible, that is. If our compilation environment has provided
int64_t, we can just make our int64 type be that, and not have to mess
around with multi-word arithmetic at all.
This commit is contained in:
Simon Tatham
2023-05-01 13:49:54 +01:00
parent c48a9f44ff
commit 628cc6785b

View File

@ -20,10 +20,6 @@
* requirements are adequately expressed by a single scalar tile
* size), and probably complicate the rest of the puzzles' API as a
* result. So I'm not sure I really want to do it.
*
* - It would be nice if we could somehow auto-detect a real `long
* long' type on the host platform and use it in place of my
* hand-hacked int64s. It'd be faster and more reliable.
*/
#include <stdio.h>
@ -37,6 +33,9 @@
#else
# include <tgmath.h>
#endif
#if HAVE_STDINT_H
# include <stdint.h>
#endif
#include "puzzles.h"
#include "tree234.h"
@ -221,6 +220,9 @@ static const char *validate_params(const game_params *params, bool full)
* integer overflow at the very core of cross().
*/
#if !HAVE_STDINT_H
/* For prehistoric C implementations, do this the hard way */
typedef struct {
long hi;
unsigned long lo;
@ -300,6 +302,21 @@ static int64 dotprod64(long a, long b, long p, long q)
return ab;
}
#else /* HAVE_STDINT_H */
typedef int64_t int64;
#define greater64(i,j) ((i) > (j))
#define sign64(i) ((i) < 0 ? -1 : (i)==0 ? 0 : +1)
#define mulu32to64(x,y) ((int64_t)(unsigned long)(x) * (unsigned long)(y))
#define mul32to64(x,y) ((int64_t)(long)(x) * (long)(y))
static int64 dotprod64(long a, long b, long p, long q)
{
return (int64)a * b + (int64)p * q;
}
#endif /* HAVE_STDINT_H */
/*
* Determine whether the line segments between a1 and a2, and
* between b1 and b2, intersect. We count it as an intersection if