Turn MOD from function to macro.
authorEric S. Raymond <esr@thyrsus.com>
Mon, 12 Jun 2017 21:33:21 +0000 (17:33 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Mon, 12 Jun 2017 21:33:21 +0000 (17:33 -0400)
I experimented with expanding it to ((N % M) everywhere, but in context
the MOD(N, M) notation seems easier to read.

advent.h
misc.c

index e75a1cd09f428f0868cbfd60f3fa1ee82fecbb23..f831a7b487d8a472bf00ca6748790e05374961e4 100644 (file)
--- a/advent.h
+++ b/advent.h
@@ -114,7 +114,6 @@ extern void BUG(long) __attribute__((noreturn));
 extern bool MAPLIN(FILE *);
 extern void TYPE(void);
 extern void DATIME(long*, long*);
 extern bool MAPLIN(FILE *);
 extern void TYPE(void);
 extern void DATIME(long*, long*);
-extern long MOD(long,long);
 
 extern void set_seed(long);
 extern unsigned long get_next_lcg_value(void);
 
 extern void set_seed(long);
 extern unsigned long get_next_lcg_value(void);
@@ -122,8 +121,8 @@ extern long randrange(long);
 extern void score(long);
 extern int saveresume(FILE *, bool);
 
 extern void score(long);
 extern int saveresume(FILE *, bool);
 
-/*  Statement functions
- *
+/*
+ *  MOD(N,M)   = Arithmetic modulus
  *  AT(OBJ)    = true if on either side of two-placed object
  *  CNDBIT(L,N) = true if COND(L) has bit n set (bit 0 is units bit)
  *  DARK(LOC)   = true if location "LOC" is dark
  *  AT(OBJ)    = true if on either side of two-placed object
  *  CNDBIT(L,N) = true if COND(L) has bit n set (bit 0 is units bit)
  *  DARK(LOC)   = true if location "LOC" is dark
@@ -136,6 +135,7 @@ extern int saveresume(FILE *, bool);
  *  PCT(N)      = true N% of the time (N integer from 0 to 100)
  *  TOTING(OBJ) = true if the OBJ is being carried */
 
  *  PCT(N)      = true N% of the time (N integer from 0 to 100)
  *  TOTING(OBJ) = true if the OBJ is being carried */
 
+#define MOD(N,M)       ((N) % (M))
 #define TOTING(OBJ)    (game.place[OBJ] == -1)
 #define AT(OBJ) (game.place[OBJ] == game.loc || game.fixed[OBJ] == game.loc)
 #define HERE(OBJ)      (AT(OBJ) || TOTING(OBJ))
 #define TOTING(OBJ)    (game.place[OBJ] == -1)
 #define AT(OBJ) (game.place[OBJ] == game.loc || game.fixed[OBJ] == game.loc)
 #define HERE(OBJ)      (AT(OBJ) || TOTING(OBJ))
diff --git a/misc.c b/misc.c
index e6f17abbddcc236ae726dc91e15d938c51a9ec38..d89b4058fbcfd003329b3a470b8fed765b7ba93e 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -698,7 +698,4 @@ void DATIME(long* d, long* t)
     *t = (long) tv.tv_usec;
 }
 
     *t = (long) tv.tv_usec;
 }
 
-long MOD(long n, long m) 
-{
-    return(n%m);
-}
+/* end */