mirror of
git://git.tartarus.org/simon/puzzles.git
synced 2025-04-21 08:01:30 -07:00
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:
25
untangle.c
25
untangle.c
@ -20,10 +20,6 @@
|
|||||||
* requirements are adequately expressed by a single scalar tile
|
* requirements are adequately expressed by a single scalar tile
|
||||||
* size), and probably complicate the rest of the puzzles' API as a
|
* size), and probably complicate the rest of the puzzles' API as a
|
||||||
* result. So I'm not sure I really want to do it.
|
* 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>
|
#include <stdio.h>
|
||||||
@ -37,6 +33,9 @@
|
|||||||
#else
|
#else
|
||||||
# include <tgmath.h>
|
# include <tgmath.h>
|
||||||
#endif
|
#endif
|
||||||
|
#if HAVE_STDINT_H
|
||||||
|
# include <stdint.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "puzzles.h"
|
#include "puzzles.h"
|
||||||
#include "tree234.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().
|
* integer overflow at the very core of cross().
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if !HAVE_STDINT_H
|
||||||
|
/* For prehistoric C implementations, do this the hard way */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
long hi;
|
long hi;
|
||||||
unsigned long lo;
|
unsigned long lo;
|
||||||
@ -300,6 +302,21 @@ static int64 dotprod64(long a, long b, long p, long q)
|
|||||||
return ab;
|
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
|
* Determine whether the line segments between a1 and a2, and
|
||||||
* between b1 and b2, intersect. We count it as an intersection if
|
* between b1 and b2, intersect. We count it as an intersection if
|
||||||
|
Reference in New Issue
Block a user