add function to compare (order) two numbers

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@10152 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2004-07-04 03:55:16 +00:00
parent 2e0ea64b27
commit 5ff6c419d6
2 changed files with 25 additions and 0 deletions

View File

@ -231,6 +231,28 @@ equal128 (qofint128 a, qofint128 b)
return 1;
}
/** Return returns 1 if a>b, -1 if b>a, 0 if a == b */
inline int
cmp128 (qofint128 a, qofint128 b)
{
if ((0 == a.isneg) && b.isneg) return 1;
if (a.isneg && (0 == b.isneg)) return -1;
if (0 == a.isneg)
{
if (a.hi > b.hi) return 1;
if (a.hi < b.hi) return -1;
if (a.lo > b.lo) return 1;
if (a.lo < b.lo) return -1;
return 0;
}
if (a.hi > b.hi) return -1;
if (a.hi < b.hi) return 1;
if (a.lo > b.lo) return -1;
if (a.lo < b.lo) return 1;
return 0;
}
/** Return the greatest common factor of two 64-bit numbers */
inline guint64
gcf64(guint64 num, guint64 denom)

View File

@ -42,6 +42,9 @@ typedef struct {
/** Return true of two numbers are equal */
inline gboolean equal128 (qofint128 a, qofint128 b);
/** Return returns 1 if a>b, -1 if b>a, 0 if a == b */
inline int cmp128 (qofint128 a, qofint128 b);
/** Shift right by one bit (i.e. divide by two) */
inline qofint128 shift128 (qofint128 x);