[gegl/samplers] lohalo: Knuth's floored division by power of 2 implemented with right shift (assumes two's complemen
- From: Nicolas Robidoux <nrobidoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/samplers] lohalo: Knuth's floored division by power of 2 implemented with right shift (assumes two's complemen
- Date: Tue, 28 Jun 2011 19:46:19 +0000 (UTC)
commit 48052c3c8bf6a6bca6de403919b1ca7fe574ea7a
Author: Nicolas Robidoux <nicolas robidoux gmail com>
Date: Tue Jun 28 15:46:14 2011 -0400
lohalo: Knuth's floored division by power of 2 implemented with right shift (assumes two's complement arch.)
gegl/buffer/gegl-sampler-lohalo.c | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
---
diff --git a/gegl/buffer/gegl-sampler-lohalo.c b/gegl/buffer/gegl-sampler-lohalo.c
index 3fa6c79..5d11d0d 100644
--- a/gegl/buffer/gegl-sampler-lohalo.c
+++ b/gegl/buffer/gegl-sampler-lohalo.c
@@ -187,8 +187,16 @@
* Special case of of Knuth's floored division, that is:
*
* FLOORED_DIVISION(a,b) (((a) - ((a)<0 ? (b)-1 : 0)) / (b))
+ *
+ * When b is 2, this gives, for example,
+ *
+ * FLOORED_DIVISION_BY_2(a) (((a) - ((a)>=0 ? 0 : 1)) / 2)
+ *
+ * On a two's complement machine, this is even simpler:
+ *
+ * FLOORED_DIVISION_BY_2(a) ( (a)>>1 )
*/
-#define LOHALO_FLOORED_DIVISION_BY_2(a) (((a) - ((a)>=0 ? 0 : 1)) / 2)
+#define LOHALO_FLOORED_DIVISION_BY_2(a) ( (a)>>1 )
/*
* General convention: Looking at the image as a (linear algebra)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]