summaryrefslogtreecommitdiffstats
path: root/pbn_cmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'pbn_cmp.c')
-rw-r--r--pbn_cmp.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/pbn_cmp.c b/pbn_cmp.c
new file mode 100644
index 0000000..1a2518d
--- /dev/null
+++ b/pbn_cmp.c
@@ -0,0 +1,45 @@
+/* ----------------------------------------------------------------------- *
+ *
+ * Copyright 2007 H. Peter Anvin - All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, Inc.,
+ * 59 Temple Place Ste 330, Boston MA 02111-1307, USA; version 2.1,
+ * incorporated herein by reference.
+ *
+ * ----------------------------------------------------------------------- */
+
+/*
+ * pbn_cmp.c
+ */
+
+#include "pbnint.h"
+
+int pbn_cmp(struct pbn *s1, struct pbn *s2)
+{
+ int lt = s1->minus ? 1 : -1;
+ int gt = -lt;
+ int i;
+
+ if (s1->minus != s2->minus)
+ return gt;
+
+ if (s1->bits < s2->bits)
+ return lt;
+ else if (s1->bits > s2->bits)
+ return gt;
+
+ i = (s1->bits+PBN_ATOM_BITS-1)/PBN_ATOM_BITS;
+ while (i >= 0) {
+ if (s1->num[i] > s2->num[i])
+ return gt;
+ else if (s1->num[i] < s2->num[i])
+ return lt;
+ i--;
+ }
+
+ return 0;
+}
+
+