# (wrong string) ée

From: <git_AT_suckless.org>
Date: Mon, 3 Jul 2017 14:06:19 +0200 (CEST)

commit c91c5cb8e892f1c19c970cef033cc03c9f47f98a
Author: Mattias Andrée <maandree_AT_kth.se>
AuthorDate: Sun Jul 2 17:30:22 2017 +0200
Commit: Mattias Andrée <maandree_AT_kth.se>
CommitDate: Sun Jul 2 17:30:22 2017 +0200

Add mod to blind-arithm

Signed-off-by: Mattias Andrée <maandree_AT_kth.se>

diff --git a/man/blind-arithm.1 b/man/blind-arithm.1
index 5b559ef..22c1188 100644
--- a/man/blind-arithm.1
+++ b/man/blind-arithm.1
_AT_@ -41,6 +41,10 @@ Calculate the product of the operands.
.B div
Divide the left-hand operand by the right-hand operand.
.TP
+.B mod
+Calculate the modulus of left-hand operand and the right-hand operand.
+The result is always non-negative.
+.TP
.B exp
Raise the left-hand operand to the
.IR n th
diff --git a/src/blind-arithm.c b/src/blind-arithm.c
index 420f452..d392557 100644
--- a/src/blind-arithm.c
+++ b/src/blind-arithm.c
_AT_@ -16,6 +16,7 @@ typedef void (*process_func)(struct stream *left, struct stream *right, size_t n
X(sub, *lh -= rh, PIXFMT, TYPE)\
X(mul, *lh *= rh, PIXFMT, TYPE)\
X(div, *lh /= rh, PIXFMT, TYPE)\
+ X(mod, *lh = posmod(*lh, rh), PIXFMT, TYPE)\
X(exp, *lh = pow(*lh, rh), PIXFMT, TYPE)\
X(log, *lh = log2(*lh) / log2(rh), PIXFMT, TYPE)\
X(min, *lh = MIN(*lh, rh), PIXFMT, TYPE)\
diff --git a/src/video-math.h b/src/video-math.h
index 709afb9..fe0e604 100644
--- a/src/video-math.h
+++ b/src/video-math.h
_AT_@ -17,6 +17,20 @@ nnpowf(float a, float b)
return neg ? -a : a;
}

+static inline double
+posmod(double a, double b)
+{
+ double x = fmod(a, b);
+ return x < 0 ? x + b : x;
+}
+
+static inline float
+posmodf(float a, float b)
+{
+ float x = fmodf(a, b);
+ return x < 0 ? x + b : x;
+}
+
#define GENERIC(TYPE, FUNC, ...)\
TYPE: FUNC(__VA_ARGS__),\
TYPE *: FUNC(__VA_ARGS__),\
_AT_@ -52,6 +66,8 @@ nnpowf(float a, float b)
#define g_isinf(...) MATH_GENERIC_1(isinf, __VA_ARGS__)
#define g_isfinite(...) MATH_GENERIC_1(isfinite, __VA_ARGS__)
#define nnpow(...) MATH_GENERIC_N(nnpow, __VA_ARGS__)
+#define mod(...) MATH_GENERIC_N(fmod, __VA_ARGS__)
+#define posmod(...) MATH_GENERIC_N(posmod, __VA_ARGS__)

#define srgb_encode(...) BLIND_GENERIC_1(srgb_encode, __VA_ARGS__)
#define srgb_decode(...) BLIND_GENERIC_1(srgb_decode, __VA_ARGS__)
Received on Mon Jul 03 2017 - 14:06:19 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 03 2017 - 14:13:13 CEST