[Gnucash-changes] add a shift-right (divide by two) function

Linas Vepstas linas at cvs.gnucash.org
Sun Jun 27 16:06:36 EDT 2004


Log Message:
-----------
add a shift-right (divide by two) function

Modified Files:
--------------
    gnucash/src/engine:
        qofmath128.c
        qofmath128.h

Revision Data
-------------
Index: qofmath128.h
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofmath128.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lsrc/engine/qofmath128.h -Lsrc/engine/qofmath128.h -u -r1.1 -r1.2
--- src/engine/qofmath128.h
+++ src/engine/qofmath128.h
@@ -71,6 +71,9 @@
 /** Add a pair of 128-bit numbers, returning a 128-bit number */
 inline qofint128 add128 (qofint128 a, qofint128 b);
 
+/** Shift right by one bit (i.e. divide by two) */
+inline qofint128 shift128 (qofint128 x);
+
 #endif
 
 /** @} */
Index: qofmath128.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/qofmath128.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lsrc/engine/qofmath128.c -Lsrc/engine/qofmath128.c -u -r1.2 -r1.3
--- src/engine/qofmath128.c
+++ src/engine/qofmath128.c
@@ -278,6 +278,28 @@
   return sum;
 }
 
+/** Shift right by one bit (i.e. divide by two) */
+inline qofint128
+shift128 (qofint128 x)
+{
+  guint64 sbit = x.hi & 0x1;
+  x.hi >>= 1;
+  x.lo >>= 1;
+  if (sbit)
+  {
+    sbit = 1<<30;  /* in two step to avoid 1ULL<<63 */
+    sbit <<= 33;
+    x.lo |= sbit;
+    x.isbig = 1;
+    return x;
+  }
+  if (x.hi)
+  {
+    x.isbig = 1;
+  }
+  return x;
+}
+
 #ifdef TEST_128_BIT_MULT
 static void pr (gint64 a, gint64 b)
 {


More information about the gnucash-changes mailing list