From df5f958784e350411e0b20d6a4473eb3256ac25f Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Wed, 26 Sep 2018 00:11:42 +0200 Subject: Simplify mastur to use a single lookup table. --- src/mastur.c | 5 ++--- src/mastur2.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/mastur.c b/src/mastur.c index 7826b05..39f868d 100644 --- a/src/mastur.c +++ b/src/mastur.c @@ -1,7 +1,6 @@ -static const int A[] = {0, 1, -1}; -static const int C[][3] = {{1, 1, -2}, {1, 1, -2}, {-2, 1, 1}}; +static const int C[][3] = {{0, 0, 0}, {1, 1, -2}, {2, -1, -1}}; int mastur(const int i, const int x, const int y) { - return i + A[x] * C[x][i / y % 3] * y; + return i + C[x][i / y % 3] * y; } diff --git a/src/mastur2.c b/src/mastur2.c index 1be6d1d..554fdc0 100644 --- a/src/mastur2.c +++ b/src/mastur2.c @@ -10,10 +10,9 @@ static const unsigned int divtab[244] = { #define FASTDIV(n, d) (((n) * divtab[d]) >> 16) #define FASTMOD(n, d) ((n) - (d) * FASTDIV((n), (d))) -static const int A[] = {0, 1, -1}; -static const int C[][3] = {{1, 1, -2}, {1, 1, -2}, {-2, 1, 1}}; +static const int C[][3] = {{0, 0, 0}, {1, 1, -2}, {2, -1, -1}}; int mastur2(const int i, const int x, const int y) { - return i + A[x] * C[x][FASTMOD(FASTDIV(i, y), 3)] * y; + return i + C[x][FASTMOD(FASTDIV(i, y), 3)] * y; } -- cgit