add a shift-right (divide by two) function

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@10115 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2004-06-27 20:06:36 +00:00
parent ecbd743dbb
commit 24055b8c49
2 changed files with 25 additions and 0 deletions

View File

@ -278,6 +278,28 @@ add128 (qofint128 a, qofint128 b)
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)
{

View File

@ -71,6 +71,9 @@ inline qofint128 lcm128 (guint64 a, guint64 b);
/** 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
/** @} */